PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
makefuncs.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * makefuncs.c
4 * creator functions for various nodes. The functions here are for the
5 * most frequently created nodes.
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 *
11 * IDENTIFICATION
12 * src/backend/nodes/makefuncs.c
13 *
14 *-------------------------------------------------------------------------
15 */
16#include "postgres.h"
17
18#include "catalog/pg_class.h"
19#include "catalog/pg_type.h"
20#include "nodes/makefuncs.h"
21#include "nodes/nodeFuncs.h"
22#include "utils/lsyscache.h"
23
24
25/*
26 * makeA_Expr -
27 * makes an A_Expr node
28 */
29A_Expr *
31 Node *lexpr, Node *rexpr, int location)
32{
34
35 a->kind = kind;
36 a->name = name;
37 a->lexpr = lexpr;
38 a->rexpr = rexpr;
39 a->location = location;
40 return a;
41}
42
43/*
44 * makeSimpleA_Expr -
45 * As above, given a simple (unqualified) operator name
46 */
47A_Expr *
49 Node *lexpr, Node *rexpr, int location)
50{
52
53 a->kind = kind;
54 a->name = list_make1(makeString(name));
55 a->lexpr = lexpr;
56 a->rexpr = rexpr;
57 a->location = location;
58 return a;
59}
60
61/*
62 * makeVar -
63 * creates a Var node
64 */
65Var *
66makeVar(int varno,
67 AttrNumber varattno,
68 Oid vartype,
69 int32 vartypmod,
70 Oid varcollid,
71 Index varlevelsup)
72{
73 Var *var = makeNode(Var);
74
75 var->varno = varno;
76 var->varattno = varattno;
77 var->vartype = vartype;
78 var->vartypmod = vartypmod;
79 var->varcollid = varcollid;
80 var->varlevelsup = varlevelsup;
81
82 /*
83 * Only a few callers need to make Var nodes with varreturningtype
84 * different from VAR_RETURNING_DEFAULT, non-null varnullingrels, or with
85 * varnosyn/varattnosyn different from varno/varattno. We don't provide
86 * separate arguments for them, but just initialize them to sensible
87 * default values. This reduces code clutter and chance of error for most
88 * callers.
89 */
91 var->varnullingrels = NULL;
92 var->varnosyn = (Index) varno;
93 var->varattnosyn = varattno;
94
95 /* Likewise, we just set location to "unknown" here */
96 var->location = -1;
97
98 return var;
99}
100
101/*
102 * makeVarFromTargetEntry -
103 * convenience function to create a same-level Var node from a
104 * TargetEntry
105 */
106Var *
108 TargetEntry *tle)
109{
110 return makeVar(varno,
111 tle->resno,
112 exprType((Node *) tle->expr),
113 exprTypmod((Node *) tle->expr),
114 exprCollation((Node *) tle->expr),
115 0);
116}
117
118/*
119 * makeWholeRowVar -
120 * creates a Var node representing a whole row of the specified RTE
121 *
122 * A whole-row reference is a Var with varno set to the correct range
123 * table entry, and varattno == 0 to signal that it references the whole
124 * tuple. (Use of zero here is unclean, since it could easily be confused
125 * with error cases, but it's not worth changing now.) The vartype indicates
126 * a rowtype; either a named composite type, or a domain over a named
127 * composite type (only possible if the RTE is a function returning that),
128 * or RECORD. This function encapsulates the logic for determining the
129 * correct rowtype OID to use.
130 *
131 * If allowScalar is true, then for the case where the RTE is a single function
132 * returning a non-composite result type, we produce a normal Var referencing
133 * the function's result directly, instead of the single-column composite
134 * value that the whole-row notation might otherwise suggest.
135 */
136Var *
138 int varno,
139 Index varlevelsup,
140 bool allowScalar)
141{
142 Var *result;
143 Oid toid;
144 Node *fexpr;
145
146 switch (rte->rtekind)
147 {
148 case RTE_RELATION:
149 /* relation: the rowtype is a named composite type */
150 toid = get_rel_type_id(rte->relid);
151 if (!OidIsValid(toid))
153 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
154 errmsg("relation \"%s\" does not have a composite type",
155 get_rel_name(rte->relid))));
156 result = makeVar(varno,
158 toid,
159 -1,
161 varlevelsup);
162 break;
163
164 case RTE_SUBQUERY:
165
166 /*
167 * For a standard subquery, the Var should be of RECORD type.
168 * However, if we're looking at a subquery that was expanded from
169 * a view or SRF (only possible during planning), we must use the
170 * appropriate rowtype, so that the resulting Var has the same
171 * type that we would have produced from the original RTE.
172 */
173 if (OidIsValid(rte->relid))
174 {
175 /* Subquery was expanded from a view */
176 toid = get_rel_type_id(rte->relid);
177 if (!OidIsValid(toid))
179 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
180 errmsg("relation \"%s\" does not have a composite type",
181 get_rel_name(rte->relid))));
182 }
183 else if (rte->functions)
184 {
185 /*
186 * Subquery was expanded from a set-returning function. That
187 * would not have happened if there's more than one function
188 * or ordinality was requested. We also needn't worry about
189 * the allowScalar case, since the planner doesn't use that.
190 * Otherwise this must match the RTE_FUNCTION code below.
191 */
192 Assert(!allowScalar);
193 fexpr = ((RangeTblFunction *) linitial(rte->functions))->funcexpr;
194 toid = exprType(fexpr);
195 if (!type_is_rowtype(toid))
196 toid = RECORDOID;
197 }
198 else
199 {
200 /* Normal subquery-in-FROM */
201 toid = RECORDOID;
202 }
203 result = makeVar(varno,
205 toid,
206 -1,
208 varlevelsup);
209 break;
210
211 case RTE_FUNCTION:
212
213 /*
214 * If there's more than one function, or ordinality is requested,
215 * force a RECORD result, since there's certainly more than one
216 * column involved and it can't be a known named type.
217 */
218 if (rte->funcordinality || list_length(rte->functions) != 1)
219 {
220 /* always produces an anonymous RECORD result */
221 result = makeVar(varno,
223 RECORDOID,
224 -1,
226 varlevelsup);
227 break;
228 }
229
230 fexpr = ((RangeTblFunction *) linitial(rte->functions))->funcexpr;
231 toid = exprType(fexpr);
232 if (type_is_rowtype(toid))
233 {
234 /* func returns composite; same as relation case */
235 result = makeVar(varno,
237 toid,
238 -1,
240 varlevelsup);
241 }
242 else if (allowScalar)
243 {
244 /* func returns scalar; just return its output as-is */
245 result = makeVar(varno,
246 1,
247 toid,
248 -1,
249 exprCollation(fexpr),
250 varlevelsup);
251 }
252 else
253 {
254 /* func returns scalar, but we want a composite result */
255 result = makeVar(varno,
257 RECORDOID,
258 -1,
260 varlevelsup);
261 }
262 break;
263
264 default:
265
266 /*
267 * RTE is a join, tablefunc, VALUES, CTE, etc. We represent these
268 * cases as a whole-row Var of RECORD type. (Note that in most
269 * cases the Var will be expanded to a RowExpr during planning,
270 * but that is not our concern here.)
271 */
272 result = makeVar(varno,
274 RECORDOID,
275 -1,
277 varlevelsup);
278 break;
279 }
280
281 return result;
282}
283
284/*
285 * makeTargetEntry -
286 * creates a TargetEntry node
287 */
290 AttrNumber resno,
291 char *resname,
292 bool resjunk)
293{
295
296 tle->expr = expr;
297 tle->resno = resno;
298 tle->resname = resname;
299
300 /*
301 * We always set these fields to 0. If the caller wants to change them he
302 * must do so explicitly. Few callers do that, so omitting these
303 * arguments reduces the chance of error.
304 */
305 tle->ressortgroupref = 0;
306 tle->resorigtbl = InvalidOid;
307 tle->resorigcol = 0;
308
309 tle->resjunk = resjunk;
310
311 return tle;
312}
313
314/*
315 * flatCopyTargetEntry -
316 * duplicate a TargetEntry, but don't copy substructure
317 *
318 * This is commonly used when we just want to modify the resno or substitute
319 * a new expression.
320 */
323{
325
326 Assert(IsA(src_tle, TargetEntry));
327 memcpy(tle, src_tle, sizeof(TargetEntry));
328 return tle;
329}
330
331/*
332 * makeFromExpr -
333 * creates a FromExpr node
334 */
335FromExpr *
336makeFromExpr(List *fromlist, Node *quals)
337{
339
340 f->fromlist = fromlist;
341 f->quals = quals;
342 return f;
343}
344
345/*
346 * makeConst -
347 * creates a Const node
348 */
349Const *
350makeConst(Oid consttype,
351 int32 consttypmod,
352 Oid constcollid,
353 int constlen,
354 Datum constvalue,
355 bool constisnull,
356 bool constbyval)
357{
358 Const *cnst = makeNode(Const);
359
360 /*
361 * If it's a varlena value, force it to be in non-expanded (non-toasted)
362 * format; this avoids any possible dependency on external values and
363 * improves consistency of representation, which is important for equal().
364 */
365 if (!constisnull && constlen == -1)
366 constvalue = PointerGetDatum(PG_DETOAST_DATUM(constvalue));
367
368 cnst->consttype = consttype;
369 cnst->consttypmod = consttypmod;
370 cnst->constcollid = constcollid;
371 cnst->constlen = constlen;
372 cnst->constvalue = constvalue;
373 cnst->constisnull = constisnull;
374 cnst->constbyval = constbyval;
375 cnst->location = -1; /* "unknown" */
376
377 return cnst;
378}
379
380/*
381 * makeNullConst -
382 * creates a Const node representing a NULL of the specified type/typmod
383 *
384 * This is a convenience routine that just saves a lookup of the type's
385 * storage properties.
386 */
387Const *
388makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
389{
390 int16 typLen;
391 bool typByVal;
392
393 get_typlenbyval(consttype, &typLen, &typByVal);
394 return makeConst(consttype,
395 consttypmod,
396 constcollid,
397 (int) typLen,
398 (Datum) 0,
399 true,
400 typByVal);
401}
402
403/*
404 * makeBoolConst -
405 * creates a Const node representing a boolean value (can be NULL too)
406 */
407Node *
408makeBoolConst(bool value, bool isnull)
409{
410 /* note that pg_type.h hardwires size of bool as 1 ... duplicate it */
411 return (Node *) makeConst(BOOLOID, -1, InvalidOid, 1,
412 BoolGetDatum(value), isnull, true);
413}
414
415/*
416 * makeBoolExpr -
417 * creates a BoolExpr node
418 */
419Expr *
421{
423
424 b->boolop = boolop;
425 b->args = args;
426 b->location = location;
427
428 return (Expr *) b;
429}
430
431/*
432 * makeAlias -
433 * creates an Alias node
434 *
435 * NOTE: the given name is copied, but the colnames list (if any) isn't.
436 */
437Alias *
438makeAlias(const char *aliasname, List *colnames)
439{
440 Alias *a = makeNode(Alias);
441
442 a->aliasname = pstrdup(aliasname);
443 a->colnames = colnames;
444
445 return a;
446}
447
448/*
449 * makeRelabelType -
450 * creates a RelabelType node
451 */
453makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid,
454 CoercionForm rformat)
455{
457
458 r->arg = arg;
459 r->resulttype = rtype;
460 r->resulttypmod = rtypmod;
461 r->resultcollid = rcollid;
462 r->relabelformat = rformat;
463 r->location = -1;
464
465 return r;
466}
467
468/*
469 * makeRangeVar -
470 * creates a RangeVar node (rather oversimplified case)
471 */
472RangeVar *
473makeRangeVar(char *schemaname, char *relname, int location)
474{
476
477 r->catalogname = NULL;
478 r->schemaname = schemaname;
479 r->relname = relname;
480 r->inh = true;
481 r->relpersistence = RELPERSISTENCE_PERMANENT;
482 r->alias = NULL;
483 r->location = location;
484
485 return r;
486}
487
488/*
489 * makeNotNullConstraint -
490 * creates a Constraint node for NOT NULL constraints
491 */
494{
495 Constraint *notnull;
496
497 notnull = makeNode(Constraint);
498 notnull->contype = CONSTR_NOTNULL;
499 notnull->conname = NULL;
500 notnull->is_no_inherit = false;
501 notnull->deferrable = false;
502 notnull->initdeferred = false;
503 notnull->location = -1;
504 notnull->keys = list_make1(colname);
505 notnull->is_enforced = true;
506 notnull->skip_validation = false;
507 notnull->initially_valid = true;
508
509 return notnull;
510}
511
512/*
513 * makeTypeName -
514 * build a TypeName node for an unqualified name.
515 *
516 * typmod is defaulted, but can be changed later by caller.
517 */
518TypeName *
519makeTypeName(char *typnam)
520{
522}
523
524/*
525 * makeTypeNameFromNameList -
526 * build a TypeName node for a String list representing a qualified name.
527 *
528 * typmod is defaulted, but can be changed later by caller.
529 */
530TypeName *
532{
534
535 n->names = names;
536 n->typmods = NIL;
537 n->typemod = -1;
538 n->location = -1;
539 return n;
540}
541
542/*
543 * makeTypeNameFromOid -
544 * build a TypeName node to represent a type already known by OID/typmod.
545 */
546TypeName *
548{
550
551 n->typeOid = typeOid;
552 n->typemod = typmod;
553 n->location = -1;
554 return n;
555}
556
557/*
558 * makeColumnDef -
559 * build a ColumnDef node to represent a simple column definition.
560 *
561 * Type and collation are specified by OID.
562 * Other properties are all basic to start with.
563 */
564ColumnDef *
565makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
566{
568
569 n->colname = pstrdup(colname);
570 n->typeName = makeTypeNameFromOid(typeOid, typmod);
571 n->inhcount = 0;
572 n->is_local = true;
573 n->is_not_null = false;
574 n->is_from_type = false;
575 n->storage = 0;
576 n->raw_default = NULL;
577 n->cooked_default = NULL;
578 n->collClause = NULL;
579 n->collOid = collOid;
580 n->constraints = NIL;
581 n->fdwoptions = NIL;
582 n->location = -1;
583
584 return n;
585}
586
587/*
588 * makeFuncExpr -
589 * build an expression tree representing a function call.
590 *
591 * The argument expressions must have been transformed already.
592 */
593FuncExpr *
594makeFuncExpr(Oid funcid, Oid rettype, List *args,
595 Oid funccollid, Oid inputcollid, CoercionForm fformat)
596{
597 FuncExpr *funcexpr;
598
599 funcexpr = makeNode(FuncExpr);
600 funcexpr->funcid = funcid;
601 funcexpr->funcresulttype = rettype;
602 funcexpr->funcretset = false; /* only allowed case here */
603 funcexpr->funcvariadic = false; /* only allowed case here */
604 funcexpr->funcformat = fformat;
605 funcexpr->funccollid = funccollid;
606 funcexpr->inputcollid = inputcollid;
607 funcexpr->args = args;
608 funcexpr->location = -1;
609
610 return funcexpr;
611}
612
613/*
614 * makeStringConst -
615 * build a A_Const node of type T_String for given string
616 */
617Node *
618makeStringConst(char *str, int location)
619{
621
622 n->val.sval.type = T_String;
623 n->val.sval.sval = str;
624 n->location = location;
625
626 return (Node *) n;
627}
628
629/*
630 * makeDefElem -
631 * build a DefElem node
632 *
633 * This is sufficient for the "typical" case with an unqualified option name
634 * and no special action.
635 */
636DefElem *
637makeDefElem(char *name, Node *arg, int location)
638{
639 DefElem *res = makeNode(DefElem);
640
641 res->defnamespace = NULL;
642 res->defname = name;
643 res->arg = arg;
645 res->location = location;
646
647 return res;
648}
649
650/*
651 * makeDefElemExtended -
652 * build a DefElem node with all fields available to be specified
653 */
654DefElem *
655makeDefElemExtended(char *nameSpace, char *name, Node *arg,
656 DefElemAction defaction, int location)
657{
658 DefElem *res = makeNode(DefElem);
659
660 res->defnamespace = nameSpace;
661 res->defname = name;
662 res->arg = arg;
663 res->defaction = defaction;
664 res->location = location;
665
666 return res;
667}
668
669/*
670 * makeFuncCall -
671 *
672 * Initialize a FuncCall struct with the information every caller must
673 * supply. Any non-default parameters have to be inserted by the caller.
674 */
675FuncCall *
676makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
677{
679
680 n->funcname = name;
681 n->args = args;
682 n->agg_order = NIL;
683 n->agg_filter = NULL;
684 n->over = NULL;
685 n->agg_within_group = false;
686 n->agg_star = false;
687 n->agg_distinct = false;
688 n->func_variadic = false;
689 n->funcformat = funcformat;
690 n->location = location;
691 return n;
692}
693
694/*
695 * make_opclause
696 * Creates an operator clause given its operator info, left operand
697 * and right operand (pass NULL to create single-operand clause),
698 * and collation info.
699 */
700Expr *
701make_opclause(Oid opno, Oid opresulttype, bool opretset,
702 Expr *leftop, Expr *rightop,
703 Oid opcollid, Oid inputcollid)
704{
705 OpExpr *expr = makeNode(OpExpr);
706
707 expr->opno = opno;
708 expr->opfuncid = InvalidOid;
709 expr->opresulttype = opresulttype;
710 expr->opretset = opretset;
711 expr->opcollid = opcollid;
712 expr->inputcollid = inputcollid;
713 if (rightop)
714 expr->args = list_make2(leftop, rightop);
715 else
716 expr->args = list_make1(leftop);
717 expr->location = -1;
718 return (Expr *) expr;
719}
720
721/*
722 * make_andclause
723 *
724 * Creates an 'and' clause given a list of its subclauses.
725 */
726Expr *
728{
729 BoolExpr *expr = makeNode(BoolExpr);
730
731 expr->boolop = AND_EXPR;
732 expr->args = andclauses;
733 expr->location = -1;
734 return (Expr *) expr;
735}
736
737/*
738 * make_orclause
739 *
740 * Creates an 'or' clause given a list of its subclauses.
741 */
742Expr *
744{
745 BoolExpr *expr = makeNode(BoolExpr);
746
747 expr->boolop = OR_EXPR;
748 expr->args = orclauses;
749 expr->location = -1;
750 return (Expr *) expr;
751}
752
753/*
754 * make_notclause
755 *
756 * Create a 'not' clause given the expression to be negated.
757 */
758Expr *
760{
761 BoolExpr *expr = makeNode(BoolExpr);
762
763 expr->boolop = NOT_EXPR;
764 expr->args = list_make1(notclause);
765 expr->location = -1;
766 return (Expr *) expr;
767}
768
769/*
770 * make_and_qual
771 *
772 * Variant of make_andclause for ANDing two qual conditions together.
773 * Qual conditions have the property that a NULL nodetree is interpreted
774 * as 'true'.
775 *
776 * NB: this makes no attempt to preserve AND/OR flatness; so it should not
777 * be used on a qual that has already been run through prepqual.c.
778 */
779Node *
780make_and_qual(Node *qual1, Node *qual2)
781{
782 if (qual1 == NULL)
783 return qual2;
784 if (qual2 == NULL)
785 return qual1;
786 return (Node *) make_andclause(list_make2(qual1, qual2));
787}
788
789/*
790 * The planner and executor usually represent qualification expressions
791 * as lists of boolean expressions with implicit AND semantics.
792 *
793 * These functions convert between an AND-semantics expression list and the
794 * ordinary representation of a boolean expression.
795 *
796 * Note that an empty list is considered equivalent to TRUE.
797 */
798Expr *
800{
801 if (andclauses == NIL)
802 return (Expr *) makeBoolConst(true, false);
803 else if (list_length(andclauses) == 1)
804 return (Expr *) linitial(andclauses);
805 else
806 return make_andclause(andclauses);
807}
808
809List *
811{
812 /*
813 * NB: because the parser sets the qual field to NULL in a query that has
814 * no WHERE clause, we must consider a NULL input clause as TRUE, even
815 * though one might more reasonably think it FALSE.
816 */
817 if (clause == NULL)
818 return NIL; /* NULL -> NIL list == TRUE */
819 else if (is_andclause(clause))
820 return ((BoolExpr *) clause)->args;
821 else if (IsA(clause, Const) &&
822 !((Const *) clause)->constisnull &&
823 DatumGetBool(((Const *) clause)->constvalue))
824 return NIL; /* constant TRUE input -> NIL list */
825 else
826 return list_make1(clause);
827}
828
829/*
830 * makeIndexInfo
831 * create an IndexInfo node
832 */
833IndexInfo *
834makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions,
835 List *predicates, bool unique, bool nulls_not_distinct,
836 bool isready, bool concurrent, bool summarizing,
837 bool withoutoverlaps)
838{
840
841 n->ii_NumIndexAttrs = numattrs;
842 n->ii_NumIndexKeyAttrs = numkeyattrs;
845 n->ii_Unique = unique;
846 n->ii_NullsNotDistinct = nulls_not_distinct;
847 n->ii_ReadyForInserts = isready;
848 n->ii_CheckedUnchanged = false;
849 n->ii_IndexUnchanged = false;
850 n->ii_Concurrent = concurrent;
851 n->ii_Summarizing = summarizing;
852 n->ii_WithoutOverlaps = withoutoverlaps;
853
854 /* summarizing indexes cannot contain non-key attributes */
855 Assert(!summarizing || (numkeyattrs == numattrs));
856
857 /* expressions */
858 n->ii_Expressions = expressions;
860
861 /* predicates */
862 n->ii_Predicate = predicates;
863 n->ii_PredicateState = NULL;
864
865 /* exclusion constraints */
866 n->ii_ExclusionOps = NULL;
867 n->ii_ExclusionProcs = NULL;
868 n->ii_ExclusionStrats = NULL;
869
870 /* speculative inserts */
871 n->ii_UniqueOps = NULL;
872 n->ii_UniqueProcs = NULL;
873 n->ii_UniqueStrats = NULL;
874
875 /* initialize index-build state to default */
876 n->ii_BrokenHotChain = false;
877 n->ii_ParallelWorkers = 0;
878
879 /* set up for possible use by index AM */
880 n->ii_Am = amoid;
881 n->ii_AmCache = NULL;
883
884 return n;
885}
886
887/*
888 * makeGroupingSet
889 *
890 */
892makeGroupingSet(GroupingSetKind kind, List *content, int location)
893{
895
896 n->kind = kind;
897 n->content = content;
898 n->location = location;
899 return n;
900}
901
902/*
903 * makeVacuumRelation -
904 * create a VacuumRelation node
905 */
907makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
908{
910
911 v->relation = relation;
912 v->oid = oid;
913 v->va_cols = va_cols;
914 return v;
915}
916
917/*
918 * makeJsonFormat -
919 * creates a JsonFormat node
920 */
923{
925
926 jf->format_type = type;
927 jf->encoding = encoding;
928 jf->location = location;
929
930 return jf;
931}
932
933/*
934 * makeJsonValueExpr -
935 * creates a JsonValueExpr node
936 */
938makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr,
940{
942
943 jve->raw_expr = raw_expr;
944 jve->formatted_expr = formatted_expr;
945 jve->format = format;
946
947 return jve;
948}
949
950/*
951 * makeJsonBehavior -
952 * creates a JsonBehavior node
953 */
955makeJsonBehavior(JsonBehaviorType btype, Node *expr, int location)
956{
958
959 behavior->btype = btype;
960 behavior->expr = expr;
961 behavior->location = location;
962
963 return behavior;
964}
965
966/*
967 * makeJsonKeyValue -
968 * creates a JsonKeyValue node
969 */
970Node *
972{
974
975 n->key = (Expr *) key;
977
978 return (Node *) n;
979}
980
981/*
982 * makeJsonIsPredicate -
983 * creates a JsonIsPredicate node
984 */
985Node *
987 bool unique_keys, int location)
988{
990
991 n->expr = expr;
992 n->format = format;
993 n->item_type = item_type;
994 n->unique_keys = unique_keys;
995 n->location = location;
996
997 return (Node *) n;
998}
999
1000/*
1001 * makeJsonTablePathSpec -
1002 * Make JsonTablePathSpec node from given path string and name (if any)
1003 */
1005makeJsonTablePathSpec(char *string, char *name, int string_location,
1006 int name_location)
1007{
1009
1010 Assert(string != NULL);
1011 pathspec->string = makeStringConst(string, string_location);
1012 if (name != NULL)
1013 pathspec->name = pstrdup(name);
1014
1015 pathspec->name_location = name_location;
1016 pathspec->location = string_location;
1017
1018 return pathspec;
1019}
1020
1021/*
1022 * makeJsonTablePath -
1023 * Make JsonTablePath node for given path string and name
1024 */
1026makeJsonTablePath(Const *pathvalue, char *pathname)
1027{
1029
1030 Assert(IsA(pathvalue, Const));
1031 path->value = pathvalue;
1032 path->name = pathname;
1033
1034 return path;
1035}
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:417
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
int16_t int16
Definition: c.h:497
int32_t int32
Definition: c.h:498
unsigned int Index
Definition: c.h:585
#define OidIsValid(objectId)
Definition: c.h:746
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
Assert(PointerIsAligned(start, uint64))
const char * str
static struct @165 value
int b
Definition: isn.c:74
int a
Definition: isn.c:73
char * get_rel_name(Oid relid)
Definition: lsyscache.c:2068
bool type_is_rowtype(Oid typid)
Definition: lsyscache.c:2795
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2391
Oid get_rel_type_id(Oid relid)
Definition: lsyscache.c:2119
Alias * makeAlias(const char *aliasname, List *colnames)
Definition: makefuncs.c:438
Expr * make_orclause(List *orclauses)
Definition: makefuncs.c:743
Expr * make_ands_explicit(List *andclauses)
Definition: makefuncs.c:799
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:420
VacuumRelation * makeVacuumRelation(RangeVar *relation, Oid oid, List *va_cols)
Definition: makefuncs.c:907
DefElem * makeDefElem(char *name, Node *arg, int location)
Definition: makefuncs.c:637
A_Expr * makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr, int location)
Definition: makefuncs.c:30
TypeName * makeTypeNameFromNameList(List *names)
Definition: makefuncs.c:531
Var * makeVarFromTargetEntry(int varno, TargetEntry *tle)
Definition: makefuncs.c:107
FromExpr * makeFromExpr(List *fromlist, Node *quals)
Definition: makefuncs.c:336
JsonBehavior * makeJsonBehavior(JsonBehaviorType btype, Node *expr, int location)
Definition: makefuncs.c:955
IndexInfo * makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions, List *predicates, bool unique, bool nulls_not_distinct, bool isready, bool concurrent, bool summarizing, bool withoutoverlaps)
Definition: makefuncs.c:834
JsonTablePath * makeJsonTablePath(Const *pathvalue, char *pathname)
Definition: makefuncs.c:1026
DefElem * makeDefElemExtended(char *nameSpace, char *name, Node *arg, DefElemAction defaction, int location)
Definition: makefuncs.c:655
A_Expr * makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
Definition: makefuncs.c:48
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Node * makeJsonKeyValue(Node *key, Node *value)
Definition: makefuncs.c:971
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
Definition: makefuncs.c:565
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Definition: makefuncs.c:388
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
Definition: makefuncs.c:137
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:408
RelabelType * makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
Definition: makefuncs.c:453
Node * makeStringConst(char *str, int location)
Definition: makefuncs.c:618
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:473
TypeName * makeTypeName(char *typnam)
Definition: makefuncs.c:519
Expr * make_andclause(List *andclauses)
Definition: makefuncs.c:727
FuncCall * makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
Definition: makefuncs.c:676
JsonTablePathSpec * makeJsonTablePathSpec(char *string, char *name, int string_location, int name_location)
Definition: makefuncs.c:1005
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:289
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
Definition: makefuncs.c:594
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
Definition: makefuncs.c:701
Constraint * makeNotNullConstraint(String *colname)
Definition: makefuncs.c:493
Expr * make_notclause(Expr *notclause)
Definition: makefuncs.c:759
JsonValueExpr * makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr, JsonFormat *format)
Definition: makefuncs.c:938
Node * make_and_qual(Node *qual1, Node *qual2)
Definition: makefuncs.c:780
JsonFormat * makeJsonFormat(JsonFormatType type, JsonEncoding encoding, int location)
Definition: makefuncs.c:922
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition: makefuncs.c:350
GroupingSet * makeGroupingSet(GroupingSetKind kind, List *content, int location)
Definition: makefuncs.c:892
List * make_ands_implicit(Expr *clause)
Definition: makefuncs.c:810
TypeName * makeTypeNameFromOid(Oid typeOid, int32 typmod)
Definition: makefuncs.c:547
TargetEntry * flatCopyTargetEntry(TargetEntry *src_tle)
Definition: makefuncs.c:322
Node * makeJsonIsPredicate(Node *expr, JsonFormat *format, JsonValueType item_type, bool unique_keys, int location)
Definition: makefuncs.c:986
char * pstrdup(const char *in)
Definition: mcxt.c:2322
MemoryContext CurrentMemoryContext
Definition: mcxt.c:159
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:42
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:301
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:821
static bool is_andclause(const void *clause)
Definition: nodeFuncs.h:107
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
#define makeNode(_type_)
Definition: nodes.h:161
#define castNode(_type_, nodeptr)
Definition: nodes.h:182
GroupingSetKind
Definition: parsenodes.h:1512
A_Expr_Kind
Definition: parsenodes.h:323
@ RTE_SUBQUERY
Definition: parsenodes.h:1027
@ RTE_FUNCTION
Definition: parsenodes.h:1029
@ RTE_RELATION
Definition: parsenodes.h:1026
DefElemAction
Definition: parsenodes.h:815
@ DEFELEM_UNSPEC
Definition: parsenodes.h:816
@ CONSTR_NOTNULL
Definition: parsenodes.h:2790
void * arg
static char format
NameData relname
Definition: pg_class.h:38
int32 encoding
Definition: pg_database.h:41
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define list_make1(x1)
Definition: pg_list.h:212
#define linitial(l)
Definition: pg_list.h:178
#define list_make2(x1, x2)
Definition: pg_list.h:214
static bool DatumGetBool(Datum X)
Definition: postgres.h:95
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
uintptr_t Datum
Definition: postgres.h:69
static Datum BoolGetDatum(bool X)
Definition: postgres.h:107
#define InvalidOid
Definition: postgres_ext.h:35
unsigned int Oid
Definition: postgres_ext.h:30
JsonFormatType
Definition: primnodes.h:1642
BoolExprType
Definition: primnodes.h:947
@ AND_EXPR
Definition: primnodes.h:948
@ OR_EXPR
Definition: primnodes.h:948
@ NOT_EXPR
Definition: primnodes.h:948
JsonEncoding
Definition: primnodes.h:1630
@ VAR_RETURNING_DEFAULT
Definition: primnodes.h:256
JsonBehaviorType
Definition: primnodes.h:1769
CoercionForm
Definition: primnodes.h:750
JsonValueType
Definition: primnodes.h:1726
union ValUnion val
Definition: parsenodes.h:373
ParseLoc location
Definition: parsenodes.h:375
BoolExprType boolop
Definition: primnodes.h:956
List * args
Definition: primnodes.h:957
ParseLoc location
Definition: primnodes.h:958
bool is_not_null
Definition: parsenodes.h:742
CollateClause * collClause
Definition: parsenodes.h:752
List * constraints
Definition: parsenodes.h:754
Node * cooked_default
Definition: parsenodes.h:747
char * colname
Definition: parsenodes.h:737
TypeName * typeName
Definition: parsenodes.h:738
bool is_from_type
Definition: parsenodes.h:743
List * fdwoptions
Definition: parsenodes.h:755
Node * raw_default
Definition: parsenodes.h:746
char storage
Definition: parsenodes.h:744
Oid collOid
Definition: parsenodes.h:753
bool is_local
Definition: parsenodes.h:741
int16 inhcount
Definition: parsenodes.h:740
ParseLoc location
Definition: parsenodes.h:756
Oid consttype
Definition: primnodes.h:329
bool initdeferred
Definition: parsenodes.h:2825
ParseLoc location
Definition: parsenodes.h:2866
List * keys
Definition: parsenodes.h:2837
ConstrType contype
Definition: parsenodes.h:2822
bool is_no_inherit
Definition: parsenodes.h:2829
bool is_enforced
Definition: parsenodes.h:2826
bool initially_valid
Definition: parsenodes.h:2828
bool skip_validation
Definition: parsenodes.h:2827
bool deferrable
Definition: parsenodes.h:2824
char * conname
Definition: parsenodes.h:2823
char * defnamespace
Definition: parsenodes.h:825
DefElemAction defaction
Definition: parsenodes.h:829
char * defname
Definition: parsenodes.h:826
ParseLoc location
Definition: parsenodes.h:830
Node * arg
Definition: parsenodes.h:827
Node * quals
Definition: primnodes.h:2338
List * fromlist
Definition: primnodes.h:2337
bool agg_within_group
Definition: parsenodes.h:442
CoercionForm funcformat
Definition: parsenodes.h:446
Node * agg_filter
Definition: parsenodes.h:440
List * agg_order
Definition: parsenodes.h:439
List * funcname
Definition: parsenodes.h:437
List * args
Definition: parsenodes.h:438
bool agg_star
Definition: parsenodes.h:443
bool agg_distinct
Definition: parsenodes.h:444
ParseLoc location
Definition: parsenodes.h:447
bool func_variadic
Definition: parsenodes.h:445
struct WindowDef * over
Definition: parsenodes.h:441
ParseLoc location
Definition: primnodes.h:787
Oid funcid
Definition: primnodes.h:767
List * args
Definition: primnodes.h:785
List * content
Definition: parsenodes.h:1524
ParseLoc location
Definition: parsenodes.h:1525
bool ii_Unique
Definition: execnodes.h:209
uint16 * ii_ExclusionStrats
Definition: execnodes.h:205
bool ii_BrokenHotChain
Definition: execnodes.h:215
int ii_NumIndexAttrs
Definition: execnodes.h:196
void * ii_AmCache
Definition: execnodes.h:220
bool ii_CheckedUnchanged
Definition: execnodes.h:212
Oid * ii_UniqueOps
Definition: execnodes.h:206
ExprState * ii_PredicateState
Definition: execnodes.h:202
Oid * ii_ExclusionOps
Definition: execnodes.h:203
bool ii_NullsNotDistinct
Definition: execnodes.h:210
int ii_ParallelWorkers
Definition: execnodes.h:218
bool ii_Concurrent
Definition: execnodes.h:214
uint16 * ii_UniqueStrats
Definition: execnodes.h:208
int ii_NumIndexKeyAttrs
Definition: execnodes.h:197
List * ii_ExpressionsState
Definition: execnodes.h:200
List * ii_Expressions
Definition: execnodes.h:199
bool ii_WithoutOverlaps
Definition: execnodes.h:217
bool ii_IndexUnchanged
Definition: execnodes.h:213
Oid * ii_ExclusionProcs
Definition: execnodes.h:204
Oid ii_Am
Definition: execnodes.h:219
bool ii_Summarizing
Definition: execnodes.h:216
Oid * ii_UniqueProcs
Definition: execnodes.h:207
MemoryContext ii_Context
Definition: execnodes.h:221
bool ii_ReadyForInserts
Definition: execnodes.h:211
List * ii_Predicate
Definition: execnodes.h:201
Node * expr
Definition: primnodes.h:1796
ParseLoc location
Definition: primnodes.h:1798
JsonBehaviorType btype
Definition: primnodes.h:1795
ParseLoc location
Definition: primnodes.h:1658
JsonEncoding encoding
Definition: primnodes.h:1657
JsonFormatType format_type
Definition: primnodes.h:1656
JsonFormat * format
Definition: primnodes.h:1741
JsonValueType item_type
Definition: primnodes.h:1742
ParseLoc location
Definition: primnodes.h:1744
JsonValueExpr * value
Definition: parsenodes.h:1925
ParseLoc name_location
Definition: parsenodes.h:1862
Const * value
Definition: primnodes.h:1876
Expr * formatted_expr
Definition: primnodes.h:1689
JsonFormat * format
Definition: primnodes.h:1690
Expr * raw_expr
Definition: primnodes.h:1688
Definition: pg_list.h:54
Definition: nodes.h:135
Oid opno
Definition: primnodes.h:835
List * args
Definition: primnodes.h:853
ParseLoc location
Definition: primnodes.h:856
bool funcordinality
Definition: parsenodes.h:1193
List * functions
Definition: parsenodes.h:1191
RTEKind rtekind
Definition: parsenodes.h:1061
char * relname
Definition: primnodes.h:83
bool inh
Definition: primnodes.h:86
Alias * alias
Definition: primnodes.h:92
char relpersistence
Definition: primnodes.h:89
char * catalogname
Definition: primnodes.h:77
ParseLoc location
Definition: primnodes.h:95
char * schemaname
Definition: primnodes.h:80
Oid resulttype
Definition: primnodes.h:1202
ParseLoc location
Definition: primnodes.h:1209
Expr * arg
Definition: primnodes.h:1201
Definition: value.h:64
char * sval
Definition: value.h:68
Expr * expr
Definition: primnodes.h:2219
AttrNumber resno
Definition: primnodes.h:2221
Index ressortgroupref
Definition: primnodes.h:2225
Oid typeOid
Definition: parsenodes.h:280
List * names
Definition: parsenodes.h:279
int32 typemod
Definition: parsenodes.h:284
ParseLoc location
Definition: parsenodes.h:286
List * typmods
Definition: parsenodes.h:283
RangeVar * relation
Definition: parsenodes.h:3951
Definition: primnodes.h:262
ParseLoc location
Definition: primnodes.h:310
AttrNumber varattno
Definition: primnodes.h:274
int varno
Definition: primnodes.h:269
VarReturningType varreturningtype
Definition: primnodes.h:297
Index varlevelsup
Definition: primnodes.h:294
String sval
Definition: parsenodes.h:364
String * makeString(char *str)
Definition: value.c:63
const char * type
const char * name