Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
parse_target.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * parse_target.c
4 * handle target lists
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/parser/parse_target.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include "catalog/namespace.h"
18#include "catalog/pg_type.h"
19#include "funcapi.h"
20#include "miscadmin.h"
21#include "nodes/makefuncs.h"
22#include "nodes/nodeFuncs.h"
23#include "parser/parse_coerce.h"
24#include "parser/parse_expr.h"
26#include "parser/parse_target.h"
27#include "parser/parse_type.h"
28#include "parser/parsetree.h"
29#include "utils/builtins.h"
30#include "utils/lsyscache.h"
31#include "utils/rel.h"
32
33static void markTargetListOrigin(ParseState *pstate, TargetEntry *tle,
34 Var *var, int levelsup);
36 Node *basenode,
37 const char *targetName,
38 Oid targetTypeId,
39 int32 targetTypMod,
40 Oid targetCollation,
41 List *subscripts,
42 List *indirection,
43 ListCell *next_indirection,
44 Node *rhs,
45 CoercionContext ccontext,
46 int location);
47static List *ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref,
48 bool make_target_entry);
49static List *ExpandAllTables(ParseState *pstate, int location);
51 bool make_target_entry, ParseExprKind exprKind);
53 int sublevels_up, int location,
54 bool make_target_entry);
55static List *ExpandRowReference(ParseState *pstate, Node *expr,
56 bool make_target_entry);
57static int FigureColnameInternal(Node *node, char **name);
58
59
60/*
61 * transformTargetEntry()
62 * Transform any ordinary "expression-type" node into a targetlist entry.
63 * This is exported so that parse_clause.c can generate targetlist entries
64 * for ORDER/GROUP BY items that are not already in the targetlist.
65 *
66 * node the (untransformed) parse tree for the value expression.
67 * expr the transformed expression, or NULL if caller didn't do it yet.
68 * exprKind expression kind (EXPR_KIND_SELECT_TARGET, etc)
69 * colname the column name to be assigned, or NULL if none yet set.
70 * resjunk true if the target should be marked resjunk, ie, it is not
71 * wanted in the final projected tuple.
72 */
75 Node *node,
76 Node *expr,
77 ParseExprKind exprKind,
78 char *colname,
79 bool resjunk)
80{
81 /* Transform the node if caller didn't do it already */
82 if (expr == NULL)
83 {
84 /*
85 * If it's a SetToDefault node and we should allow that, pass it
86 * through unmodified. (transformExpr will throw the appropriate
87 * error if we're disallowing it.)
88 */
89 if (exprKind == EXPR_KIND_UPDATE_SOURCE && IsA(node, SetToDefault))
90 expr = node;
91 else
92 expr = transformExpr(pstate, node, exprKind);
93 }
94
95 if (colname == NULL && !resjunk)
96 {
97 /*
98 * Generate a suitable column name for a column without any explicit
99 * 'AS ColumnName' clause.
100 */
101 colname = FigureColname(node);
102 }
103
104 return makeTargetEntry((Expr *) expr,
105 (AttrNumber) pstate->p_next_resno++,
106 colname,
107 resjunk);
108}
109
110
111/*
112 * transformTargetList()
113 * Turns a list of ResTarget's into a list of TargetEntry's.
114 *
115 * This code acts mostly the same for SELECT, UPDATE, or RETURNING lists;
116 * the main thing is to transform the given expressions (the "val" fields).
117 * The exprKind parameter distinguishes these cases when necessary.
118 */
119List *
121 ParseExprKind exprKind)
122{
123 List *p_target = NIL;
124 bool expand_star;
125 ListCell *o_target;
126
127 /* Shouldn't have any leftover multiassign items at start */
128 Assert(pstate->p_multiassign_exprs == NIL);
129
130 /* Expand "something.*" in SELECT and RETURNING, but not UPDATE */
131 expand_star = (exprKind != EXPR_KIND_UPDATE_SOURCE);
132
133 foreach(o_target, targetlist)
134 {
135 ResTarget *res = (ResTarget *) lfirst(o_target);
136
137 /*
138 * Check for "something.*". Depending on the complexity of the
139 * "something", the star could appear as the last field in ColumnRef,
140 * or as the last indirection item in A_Indirection.
141 */
142 if (expand_star)
143 {
144 if (IsA(res->val, ColumnRef))
145 {
146 ColumnRef *cref = (ColumnRef *) res->val;
147
148 if (IsA(llast(cref->fields), A_Star))
149 {
150 /* It is something.*, expand into multiple items */
151 p_target = list_concat(p_target,
152 ExpandColumnRefStar(pstate,
153 cref,
154 true));
155 continue;
156 }
157 }
158 else if (IsA(res->val, A_Indirection))
159 {
161
162 if (IsA(llast(ind->indirection), A_Star))
163 {
164 /* It is something.*, expand into multiple items */
165 p_target = list_concat(p_target,
167 ind,
168 true,
169 exprKind));
170 continue;
171 }
172 }
173 }
174
175 /*
176 * Not "something.*", or we want to treat that as a plain whole-row
177 * variable, so transform as a single expression
178 */
179 p_target = lappend(p_target,
181 res->val,
182 NULL,
183 exprKind,
184 res->name,
185 false));
186 }
187
188 /*
189 * If any multiassign resjunk items were created, attach them to the end
190 * of the targetlist. This should only happen in an UPDATE tlist. We
191 * don't need to worry about numbering of these items; transformUpdateStmt
192 * will set their resnos.
193 */
194 if (pstate->p_multiassign_exprs)
195 {
196 Assert(exprKind == EXPR_KIND_UPDATE_SOURCE);
197 p_target = list_concat(p_target, pstate->p_multiassign_exprs);
198 pstate->p_multiassign_exprs = NIL;
199 }
200
201 return p_target;
202}
203
204
205/*
206 * transformExpressionList()
207 *
208 * This is the identical transformation to transformTargetList, except that
209 * the input list elements are bare expressions without ResTarget decoration,
210 * and the output elements are likewise just expressions without TargetEntry
211 * decoration. Also, we don't expect any multiassign constructs within the
212 * list, so there's nothing to do for that. We use this for ROW() and
213 * VALUES() constructs.
214 *
215 * exprKind is not enough to tell us whether to allow SetToDefault, so
216 * an additional flag is needed for that.
217 */
218List *
220 ParseExprKind exprKind, bool allowDefault)
221{
222 List *result = NIL;
223 ListCell *lc;
224
225 foreach(lc, exprlist)
226 {
227 Node *e = (Node *) lfirst(lc);
228
229 /*
230 * Check for "something.*". Depending on the complexity of the
231 * "something", the star could appear as the last field in ColumnRef,
232 * or as the last indirection item in A_Indirection.
233 */
234 if (IsA(e, ColumnRef))
235 {
236 ColumnRef *cref = (ColumnRef *) e;
237
238 if (IsA(llast(cref->fields), A_Star))
239 {
240 /* It is something.*, expand into multiple items */
241 result = list_concat(result,
242 ExpandColumnRefStar(pstate, cref,
243 false));
244 continue;
245 }
246 }
247 else if (IsA(e, A_Indirection))
248 {
250
251 if (IsA(llast(ind->indirection), A_Star))
252 {
253 /* It is something.*, expand into multiple items */
254 result = list_concat(result,
256 false, exprKind));
257 continue;
258 }
259 }
260
261 /*
262 * Not "something.*", so transform as a single expression. If it's a
263 * SetToDefault node and we should allow that, pass it through
264 * unmodified. (transformExpr will throw the appropriate error if
265 * we're disallowing it.)
266 */
267 if (allowDefault && IsA(e, SetToDefault))
268 /* do nothing */ ;
269 else
270 e = transformExpr(pstate, e, exprKind);
271
272 result = lappend(result, e);
273 }
274
275 return result;
276}
277
278
279/*
280 * resolveTargetListUnknowns()
281 * Convert any unknown-type targetlist entries to type TEXT.
282 *
283 * We do this after we've exhausted all other ways of identifying the output
284 * column types of a query.
285 */
286void
288{
289 ListCell *l;
290
291 foreach(l, targetlist)
292 {
293 TargetEntry *tle = (TargetEntry *) lfirst(l);
294 Oid restype = exprType((Node *) tle->expr);
295
296 if (restype == UNKNOWNOID)
297 {
298 tle->expr = (Expr *) coerce_type(pstate, (Node *) tle->expr,
299 restype, TEXTOID, -1,
302 -1);
303 }
304 }
305}
306
307
308/*
309 * markTargetListOrigins()
310 * Mark targetlist columns that are simple Vars with the source
311 * table's OID and column number.
312 *
313 * Currently, this is done only for SELECT targetlists and RETURNING lists,
314 * since we only need the info if we are going to send it to the frontend.
315 */
316void
318{
319 ListCell *l;
320
321 foreach(l, targetlist)
322 {
323 TargetEntry *tle = (TargetEntry *) lfirst(l);
324
325 markTargetListOrigin(pstate, tle, (Var *) tle->expr, 0);
326 }
327}
328
329/*
330 * markTargetListOrigin()
331 * If 'var' is a Var of a plain relation, mark 'tle' with its origin
332 *
333 * levelsup is an extra offset to interpret the Var's varlevelsup correctly.
334 *
335 * Note that we do not drill down into views, but report the view as the
336 * column owner. There's also no need to drill down into joins: if we see
337 * a join alias Var, it must be a merged JOIN USING column (or possibly a
338 * whole-row Var); that is not a direct reference to any plain table column,
339 * so we don't report it.
340 */
341static void
343 Var *var, int levelsup)
344{
345 int netlevelsup;
346 RangeTblEntry *rte;
348
349 if (var == NULL || !IsA(var, Var))
350 return;
351 netlevelsup = var->varlevelsup + levelsup;
352 rte = GetRTEByRangeTablePosn(pstate, var->varno, netlevelsup);
353 attnum = var->varattno;
354
355 switch (rte->rtekind)
356 {
357 case RTE_RELATION:
358 /* It's a table or view, report it */
359 tle->resorigtbl = rte->relid;
360 tle->resorigcol = attnum;
361 break;
362 case RTE_SUBQUERY:
363 /* Subselect-in-FROM: copy up from the subselect */
365 {
367 attnum);
368
369 if (ste == NULL || ste->resjunk)
370 elog(ERROR, "subquery %s does not have attribute %d",
371 rte->eref->aliasname, attnum);
372 tle->resorigtbl = ste->resorigtbl;
373 tle->resorigcol = ste->resorigcol;
374 }
375 break;
376 case RTE_JOIN:
377 case RTE_FUNCTION:
378 case RTE_VALUES:
379 case RTE_TABLEFUNC:
381 case RTE_RESULT:
382 /* not a simple relation, leave it unmarked */
383 break;
384 case RTE_CTE:
385
386 /*
387 * CTE reference: copy up from the subquery, if possible. If the
388 * RTE is a recursive self-reference then we can't do anything
389 * because we haven't finished analyzing it yet. However, it's no
390 * big loss because we must be down inside the recursive term of a
391 * recursive CTE, and so any markings on the current targetlist
392 * are not going to affect the results anyway.
393 */
394 if (attnum != InvalidAttrNumber && !rte->self_reference)
395 {
396 CommonTableExpr *cte = GetCTEForRTE(pstate, rte, netlevelsup);
397 TargetEntry *ste;
398 List *tl = GetCTETargetList(cte);
399 int extra_cols = 0;
400
401 /*
402 * RTE for CTE will already have the search and cycle columns
403 * added, but the subquery won't, so skip looking those up.
404 */
405 if (cte->search_clause)
406 extra_cols += 1;
407 if (cte->cycle_clause)
408 extra_cols += 2;
409 if (extra_cols &&
410 attnum > list_length(tl) &&
411 attnum <= list_length(tl) + extra_cols)
412 break;
413
414 ste = get_tle_by_resno(tl, attnum);
415 if (ste == NULL || ste->resjunk)
416 elog(ERROR, "CTE %s does not have attribute %d",
417 rte->eref->aliasname, attnum);
418 tle->resorigtbl = ste->resorigtbl;
419 tle->resorigcol = ste->resorigcol;
420 }
421 break;
422 case RTE_GROUP:
423 /* We couldn't get here: the RTE_GROUP RTE has not been added */
424 break;
425 }
426}
427
428
429/*
430 * transformAssignedExpr()
431 * This is used in INSERT and UPDATE statements only. It prepares an
432 * expression for assignment to a column of the target table.
433 * This includes coercing the given value to the target column's type
434 * (if necessary), and dealing with any subfield names or subscripts
435 * attached to the target column itself. The input expression has
436 * already been through transformExpr().
437 *
438 * pstate parse state
439 * expr expression to be modified
440 * exprKind indicates which type of statement we're dealing with
441 * colname target column name (ie, name of attribute to be assigned to)
442 * attrno target attribute number
443 * indirection subscripts/field names for target column, if any
444 * location error cursor position for the target column, or -1
445 *
446 * Returns the modified expression.
447 *
448 * Note: location points at the target column name (SET target or INSERT
449 * column name list entry), and must therefore be -1 in an INSERT that
450 * omits the column name list. So we should usually prefer to use
451 * exprLocation(expr) for errors that can happen in a default INSERT.
452 */
453Expr *
455 Expr *expr,
456 ParseExprKind exprKind,
457 const char *colname,
458 int attrno,
459 List *indirection,
460 int location)
461{
462 Relation rd = pstate->p_target_relation;
463 Oid type_id; /* type of value provided */
464 Oid attrtype; /* type of target column */
465 int32 attrtypmod;
466 Oid attrcollation; /* collation of target column */
467 ParseExprKind sv_expr_kind;
468
469 /*
470 * Save and restore identity of expression type we're parsing. We must
471 * set p_expr_kind here because we can parse subscripts without going
472 * through transformExpr().
473 */
474 Assert(exprKind != EXPR_KIND_NONE);
475 sv_expr_kind = pstate->p_expr_kind;
476 pstate->p_expr_kind = exprKind;
477
478 Assert(rd != NULL);
479 if (attrno <= 0)
481 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
482 errmsg("cannot assign to system column \"%s\"",
483 colname),
484 parser_errposition(pstate, location)));
485 attrtype = attnumTypeId(rd, attrno);
486 attrtypmod = TupleDescAttr(rd->rd_att, attrno - 1)->atttypmod;
487 attrcollation = TupleDescAttr(rd->rd_att, attrno - 1)->attcollation;
488
489 /*
490 * If the expression is a DEFAULT placeholder, insert the attribute's
491 * type/typmod/collation into it so that exprType etc will report the
492 * right things. (We expect that the eventually substituted default
493 * expression will in fact have this type and typmod. The collation
494 * likely doesn't matter, but let's set it correctly anyway.) Also,
495 * reject trying to update a subfield or array element with DEFAULT, since
496 * there can't be any default for portions of a column.
497 */
498 if (expr && IsA(expr, SetToDefault))
499 {
500 SetToDefault *def = (SetToDefault *) expr;
501
502 def->typeId = attrtype;
503 def->typeMod = attrtypmod;
504 def->collation = attrcollation;
505 if (indirection)
506 {
507 if (IsA(linitial(indirection), A_Indices))
509 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
510 errmsg("cannot set an array element to DEFAULT"),
511 parser_errposition(pstate, location)));
512 else
514 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
515 errmsg("cannot set a subfield to DEFAULT"),
516 parser_errposition(pstate, location)));
517 }
518 }
519
520 /* Now we can use exprType() safely. */
521 type_id = exprType((Node *) expr);
522
523 /*
524 * If there is indirection on the target column, prepare an array or
525 * subfield assignment expression. This will generate a new column value
526 * that the source value has been inserted into, which can then be placed
527 * in the new tuple constructed by INSERT or UPDATE.
528 */
529 if (indirection)
530 {
531 Node *colVar;
532
533 if (pstate->p_is_insert)
534 {
535 /*
536 * The command is INSERT INTO table (col.something) ... so there
537 * is not really a source value to work with. Insert a NULL
538 * constant as the source value.
539 */
540 colVar = (Node *) makeNullConst(attrtype, attrtypmod,
541 attrcollation);
542 }
543 else
544 {
545 /*
546 * Build a Var for the column to be updated.
547 */
548 Var *var;
549
550 var = makeVar(pstate->p_target_nsitem->p_rtindex, attrno,
551 attrtype, attrtypmod, attrcollation, 0);
552 var->location = location;
553
554 colVar = (Node *) var;
555 }
556
557 expr = (Expr *)
559 colVar,
560 colname,
561 false,
562 attrtype,
563 attrtypmod,
564 attrcollation,
565 indirection,
566 list_head(indirection),
567 (Node *) expr,
569 location);
570 }
571 else
572 {
573 /*
574 * For normal non-qualified target column, do type checking and
575 * coercion.
576 */
577 Node *orig_expr = (Node *) expr;
578
579 expr = (Expr *)
581 orig_expr, type_id,
582 attrtype, attrtypmod,
585 -1);
586 if (expr == NULL)
588 (errcode(ERRCODE_DATATYPE_MISMATCH),
589 errmsg("column \"%s\" is of type %s"
590 " but expression is of type %s",
591 colname,
592 format_type_be(attrtype),
593 format_type_be(type_id)),
594 errhint("You will need to rewrite or cast the expression."),
595 parser_errposition(pstate, exprLocation(orig_expr))));
596 }
597
598 pstate->p_expr_kind = sv_expr_kind;
599
600 return expr;
601}
602
603
604/*
605 * updateTargetListEntry()
606 * This is used in UPDATE statements (and ON CONFLICT DO UPDATE)
607 * only. It prepares an UPDATE TargetEntry for assignment to a
608 * column of the target table. This includes coercing the given
609 * value to the target column's type (if necessary), and dealing with
610 * any subfield names or subscripts attached to the target column
611 * itself.
612 *
613 * pstate parse state
614 * tle target list entry to be modified
615 * colname target column name (ie, name of attribute to be assigned to)
616 * attrno target attribute number
617 * indirection subscripts/field names for target column, if any
618 * location error cursor position (should point at column name), or -1
619 */
620void
622 TargetEntry *tle,
623 char *colname,
624 int attrno,
625 List *indirection,
626 int location)
627{
628 /* Fix up expression as needed */
629 tle->expr = transformAssignedExpr(pstate,
630 tle->expr,
632 colname,
633 attrno,
634 indirection,
635 location);
636
637 /*
638 * Set the resno to identify the target column --- the rewriter and
639 * planner depend on this. We also set the resname to identify the target
640 * column, but this is only for debugging purposes; it should not be
641 * relied on. (In particular, it might be out of date in a stored rule.)
642 */
643 tle->resno = (AttrNumber) attrno;
644 tle->resname = colname;
645}
646
647
648/*
649 * Process indirection (field selection or subscripting) of the target
650 * column in INSERT/UPDATE/assignment. This routine recurses for multiple
651 * levels of indirection --- but note that several adjacent A_Indices nodes
652 * in the indirection list are treated as a single multidimensional subscript
653 * operation.
654 *
655 * In the initial call, basenode is a Var for the target column in UPDATE,
656 * or a null Const of the target's type in INSERT, or a Param for the target
657 * variable in PL/pgSQL assignment. In recursive calls, basenode is NULL,
658 * indicating that a substitute node should be consed up if needed.
659 *
660 * targetName is the name of the field or subfield we're assigning to, and
661 * targetIsSubscripting is true if we're subscripting it. These are just for
662 * error reporting.
663 *
664 * targetTypeId, targetTypMod, targetCollation indicate the datatype and
665 * collation of the object to be assigned to (initially the target column,
666 * later some subobject).
667 *
668 * indirection is the list of indirection nodes, and indirection_cell is the
669 * start of the sublist remaining to process. When it's NULL, we're done
670 * recursing and can just coerce and return the RHS.
671 *
672 * rhs is the already-transformed value to be assigned; note it has not been
673 * coerced to any particular type.
674 *
675 * ccontext is the coercion level to use while coercing the rhs. For
676 * normal statements it'll be COERCION_ASSIGNMENT, but PL/pgSQL uses
677 * a special value.
678 *
679 * location is the cursor error position for any errors. (Note: this points
680 * to the head of the target clause, eg "foo" in "foo.bar[baz]". Later we
681 * might want to decorate indirection cells with their own location info,
682 * in which case the location argument could probably be dropped.)
683 */
684Node *
686 Node *basenode,
687 const char *targetName,
688 bool targetIsSubscripting,
689 Oid targetTypeId,
690 int32 targetTypMod,
691 Oid targetCollation,
692 List *indirection,
693 ListCell *indirection_cell,
694 Node *rhs,
695 CoercionContext ccontext,
696 int location)
697{
698 Node *result;
699 List *subscripts = NIL;
700 ListCell *i;
701
702 if (indirection_cell && !basenode)
703 {
704 /*
705 * Set up a substitution. We abuse CaseTestExpr for this. It's safe
706 * to do so because the only nodes that will be above the CaseTestExpr
707 * in the finished expression will be FieldStore and SubscriptingRef
708 * nodes. (There could be other stuff in the tree, but it will be
709 * within other child fields of those node types.)
710 */
712
713 ctest->typeId = targetTypeId;
714 ctest->typeMod = targetTypMod;
715 ctest->collation = targetCollation;
716 basenode = (Node *) ctest;
717 }
718
719 /*
720 * We have to split any field-selection operations apart from
721 * subscripting. Adjacent A_Indices nodes have to be treated as a single
722 * multidimensional subscript operation.
723 */
724 for_each_cell(i, indirection, indirection_cell)
725 {
726 Node *n = lfirst(i);
727
728 if (IsA(n, A_Indices))
729 subscripts = lappend(subscripts, n);
730 else if (IsA(n, A_Star))
731 {
733 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
734 errmsg("row expansion via \"*\" is not supported here"),
735 parser_errposition(pstate, location)));
736 }
737 else
738 {
739 FieldStore *fstore;
740 Oid baseTypeId;
741 int32 baseTypeMod;
742 Oid typrelid;
744 Oid fieldTypeId;
745 int32 fieldTypMod;
746 Oid fieldCollation;
747
748 Assert(IsA(n, String));
749
750 /* process subscripts before this field selection */
751 if (subscripts)
752 {
753 /* recurse, and then return because we're done */
754 return transformAssignmentSubscripts(pstate,
755 basenode,
756 targetName,
757 targetTypeId,
758 targetTypMod,
759 targetCollation,
760 subscripts,
761 indirection,
762 i,
763 rhs,
764 ccontext,
765 location);
766 }
767
768 /* No subscripts, so can process field selection here */
769
770 /*
771 * Look up the composite type, accounting for possibility that
772 * what we are given is a domain over composite.
773 */
774 baseTypeMod = targetTypMod;
775 baseTypeId = getBaseTypeAndTypmod(targetTypeId, &baseTypeMod);
776
777 typrelid = typeidTypeRelid(baseTypeId);
778 if (!typrelid)
780 (errcode(ERRCODE_DATATYPE_MISMATCH),
781 errmsg("cannot assign to field \"%s\" of column \"%s\" because its type %s is not a composite type",
782 strVal(n), targetName,
783 format_type_be(targetTypeId)),
784 parser_errposition(pstate, location)));
785
786 attnum = get_attnum(typrelid, strVal(n));
789 (errcode(ERRCODE_UNDEFINED_COLUMN),
790 errmsg("cannot assign to field \"%s\" of column \"%s\" because there is no such column in data type %s",
791 strVal(n), targetName,
792 format_type_be(targetTypeId)),
793 parser_errposition(pstate, location)));
794 if (attnum < 0)
796 (errcode(ERRCODE_UNDEFINED_COLUMN),
797 errmsg("cannot assign to system column \"%s\"",
798 strVal(n)),
799 parser_errposition(pstate, location)));
800
802 &fieldTypeId, &fieldTypMod, &fieldCollation);
803
804 /* recurse to create appropriate RHS for field assign */
806 NULL,
807 strVal(n),
808 false,
809 fieldTypeId,
810 fieldTypMod,
811 fieldCollation,
812 indirection,
813 lnext(indirection, i),
814 rhs,
815 ccontext,
816 location);
817
818 /* and build a FieldStore node */
819 fstore = makeNode(FieldStore);
820 fstore->arg = (Expr *) basenode;
821 fstore->newvals = list_make1(rhs);
822 fstore->fieldnums = list_make1_int(attnum);
823 fstore->resulttype = baseTypeId;
824
825 /*
826 * If target is a domain, apply constraints. Notice that this
827 * isn't totally right: the expression tree we build would check
828 * the domain's constraints on a composite value with only this
829 * one field populated or updated, possibly leading to an unwanted
830 * failure. The rewriter will merge together any subfield
831 * assignments to the same table column, resulting in the domain's
832 * constraints being checked only once after we've assigned to all
833 * the fields that the INSERT or UPDATE means to.
834 */
835 if (baseTypeId != targetTypeId)
836 return coerce_to_domain((Node *) fstore,
837 baseTypeId, baseTypeMod,
838 targetTypeId,
841 location,
842 false);
843
844 return (Node *) fstore;
845 }
846 }
847
848 /* process trailing subscripts, if any */
849 if (subscripts)
850 {
851 /* recurse, and then return because we're done */
852 return transformAssignmentSubscripts(pstate,
853 basenode,
854 targetName,
855 targetTypeId,
856 targetTypMod,
857 targetCollation,
858 subscripts,
859 indirection,
860 NULL,
861 rhs,
862 ccontext,
863 location);
864 }
865
866 /* base case: just coerce RHS to match target type ID */
867
868 result = coerce_to_target_type(pstate,
869 rhs, exprType(rhs),
870 targetTypeId, targetTypMod,
871 ccontext,
873 -1);
874 if (result == NULL)
875 {
876 if (targetIsSubscripting)
878 (errcode(ERRCODE_DATATYPE_MISMATCH),
879 errmsg("subscripted assignment to \"%s\" requires type %s"
880 " but expression is of type %s",
881 targetName,
882 format_type_be(targetTypeId),
884 errhint("You will need to rewrite or cast the expression."),
885 parser_errposition(pstate, location)));
886 else
888 (errcode(ERRCODE_DATATYPE_MISMATCH),
889 errmsg("subfield \"%s\" is of type %s"
890 " but expression is of type %s",
891 targetName,
892 format_type_be(targetTypeId),
894 errhint("You will need to rewrite or cast the expression."),
895 parser_errposition(pstate, location)));
896 }
897
898 return result;
899}
900
901/*
902 * helper for transformAssignmentIndirection: process container assignment
903 */
904static Node *
906 Node *basenode,
907 const char *targetName,
908 Oid targetTypeId,
909 int32 targetTypMod,
910 Oid targetCollation,
911 List *subscripts,
912 List *indirection,
913 ListCell *next_indirection,
914 Node *rhs,
915 CoercionContext ccontext,
916 int location)
917{
918 Node *result;
919 SubscriptingRef *sbsref;
920 Oid containerType;
921 int32 containerTypMod;
922 Oid typeNeeded;
923 int32 typmodNeeded;
924 Oid collationNeeded;
925
926 Assert(subscripts != NIL);
927
928 /* Identify the actual container type involved */
929 containerType = targetTypeId;
930 containerTypMod = targetTypMod;
931 transformContainerType(&containerType, &containerTypMod);
932
933 /* Process subscripts and identify required type for RHS */
934 sbsref = transformContainerSubscripts(pstate,
935 basenode,
936 containerType,
937 containerTypMod,
938 subscripts,
939 true);
940
941 typeNeeded = sbsref->refrestype;
942 typmodNeeded = sbsref->reftypmod;
943
944 /*
945 * Container normally has same collation as its elements, but there's an
946 * exception: we might be subscripting a domain over a container type. In
947 * that case use collation of the base type. (This is shaky for arbitrary
948 * subscripting semantics, but it doesn't matter all that much since we
949 * only use this to label the collation of a possible CaseTestExpr.)
950 */
951 if (containerType == targetTypeId)
952 collationNeeded = targetCollation;
953 else
954 collationNeeded = get_typcollation(containerType);
955
956 /* recurse to create appropriate RHS for container assign */
958 NULL,
959 targetName,
960 true,
961 typeNeeded,
962 typmodNeeded,
963 collationNeeded,
964 indirection,
965 next_indirection,
966 rhs,
967 ccontext,
968 location);
969
970 /*
971 * Insert the already-properly-coerced RHS into the SubscriptingRef. Then
972 * set refrestype and reftypmod back to the container type's values.
973 */
974 sbsref->refassgnexpr = (Expr *) rhs;
975 sbsref->refrestype = containerType;
976 sbsref->reftypmod = containerTypMod;
977
978 result = (Node *) sbsref;
979
980 /*
981 * If target was a domain over container, need to coerce up to the domain.
982 * As in transformAssignmentIndirection, this coercion is premature if the
983 * query assigns to multiple elements of the container; but we'll fix that
984 * during query rewrite.
985 */
986 if (containerType != targetTypeId)
987 {
988 Oid resulttype = exprType(result);
989
990 result = coerce_to_target_type(pstate,
991 result, resulttype,
992 targetTypeId, targetTypMod,
993 ccontext,
995 -1);
996 /* can fail if we had int2vector/oidvector, but not for true domains */
997 if (result == NULL)
999 (errcode(ERRCODE_CANNOT_COERCE),
1000 errmsg("cannot cast type %s to %s",
1001 format_type_be(resulttype),
1002 format_type_be(targetTypeId)),
1003 parser_errposition(pstate, location)));
1004 }
1005
1006 return result;
1007}
1008
1009
1010/*
1011 * checkInsertTargets -
1012 * generate a list of INSERT column targets if not supplied, or
1013 * test supplied column names to make sure they are in target table.
1014 * Also return an integer list of the columns' attribute numbers.
1015 */
1016List *
1017checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
1018{
1019 *attrnos = NIL;
1020
1021 if (cols == NIL)
1022 {
1023 /*
1024 * Generate default column list for INSERT.
1025 */
1027
1028 int i;
1029
1030 for (i = 0; i < numcol; i++)
1031 {
1032 ResTarget *col;
1033 Form_pg_attribute attr;
1034
1035 attr = TupleDescAttr(pstate->p_target_relation->rd_att, i);
1036
1037 if (attr->attisdropped)
1038 continue;
1039
1040 col = makeNode(ResTarget);
1041 col->name = pstrdup(NameStr(attr->attname));
1042 col->indirection = NIL;
1043 col->val = NULL;
1044 col->location = -1;
1045 cols = lappend(cols, col);
1046 *attrnos = lappend_int(*attrnos, i + 1);
1047 }
1048 }
1049 else
1050 {
1051 /*
1052 * Do initial validation of user-supplied INSERT column list.
1053 */
1054 Bitmapset *wholecols = NULL;
1055 Bitmapset *partialcols = NULL;
1056 ListCell *tl;
1057
1058 foreach(tl, cols)
1059 {
1060 ResTarget *col = (ResTarget *) lfirst(tl);
1061 char *name = col->name;
1062 int attrno;
1063
1064 /* Lookup column name, ereport on failure */
1065 attrno = attnameAttNum(pstate->p_target_relation, name, false);
1066 if (attrno == InvalidAttrNumber)
1067 ereport(ERROR,
1068 (errcode(ERRCODE_UNDEFINED_COLUMN),
1069 errmsg("column \"%s\" of relation \"%s\" does not exist",
1070 name,
1072 parser_errposition(pstate, col->location)));
1073
1074 /*
1075 * Check for duplicates, but only of whole columns --- we allow
1076 * INSERT INTO foo (col.subcol1, col.subcol2)
1077 */
1078 if (col->indirection == NIL)
1079 {
1080 /* whole column; must not have any other assignment */
1081 if (bms_is_member(attrno, wholecols) ||
1082 bms_is_member(attrno, partialcols))
1083 ereport(ERROR,
1084 (errcode(ERRCODE_DUPLICATE_COLUMN),
1085 errmsg("column \"%s\" specified more than once",
1086 name),
1087 parser_errposition(pstate, col->location)));
1088 wholecols = bms_add_member(wholecols, attrno);
1089 }
1090 else
1091 {
1092 /* partial column; must not have any whole assignment */
1093 if (bms_is_member(attrno, wholecols))
1094 ereport(ERROR,
1095 (errcode(ERRCODE_DUPLICATE_COLUMN),
1096 errmsg("column \"%s\" specified more than once",
1097 name),
1098 parser_errposition(pstate, col->location)));
1099 partialcols = bms_add_member(partialcols, attrno);
1100 }
1101
1102 *attrnos = lappend_int(*attrnos, attrno);
1103 }
1104 }
1105
1106 return cols;
1107}
1108
1109/*
1110 * ExpandColumnRefStar()
1111 * Transforms foo.* into a list of expressions or targetlist entries.
1112 *
1113 * This handles the case where '*' appears as the last or only item in a
1114 * ColumnRef. The code is shared between the case of foo.* at the top level
1115 * in a SELECT target list (where we want TargetEntry nodes in the result)
1116 * and foo.* in a ROW() or VALUES() construct (where we want just bare
1117 * expressions).
1118 *
1119 * The referenced columns are marked as requiring SELECT access.
1120 */
1121static List *
1123 bool make_target_entry)
1124{
1125 List *fields = cref->fields;
1126 int numnames = list_length(fields);
1127
1128 if (numnames == 1)
1129 {
1130 /*
1131 * Target item is a bare '*', expand all tables
1132 *
1133 * (e.g., SELECT * FROM emp, dept)
1134 *
1135 * Since the grammar only accepts bare '*' at top level of SELECT, we
1136 * need not handle the make_target_entry==false case here.
1137 */
1138 Assert(make_target_entry);
1139 return ExpandAllTables(pstate, cref->location);
1140 }
1141 else
1142 {
1143 /*
1144 * Target item is relation.*, expand that table
1145 *
1146 * (e.g., SELECT emp.*, dname FROM emp, dept)
1147 *
1148 * Note: this code is a lot like transformColumnRef; it's tempting to
1149 * call that instead and then replace the resulting whole-row Var with
1150 * a list of Vars. However, that would leave us with the relation's
1151 * selectedCols bitmap showing the whole row as needing select
1152 * permission, as well as the individual columns. That would be
1153 * incorrect (since columns added later shouldn't need select
1154 * permissions). We could try to remove the whole-row permission bit
1155 * after the fact, but duplicating code is less messy.
1156 */
1157 char *nspname = NULL;
1158 char *relname = NULL;
1159 ParseNamespaceItem *nsitem = NULL;
1160 int levels_up;
1161 enum
1162 {
1163 CRSERR_NO_RTE,
1164 CRSERR_WRONG_DB,
1165 CRSERR_TOO_MANY
1166 } crserr = CRSERR_NO_RTE;
1167
1168 /*
1169 * Give the PreParseColumnRefHook, if any, first shot. If it returns
1170 * non-null then we should use that expression.
1171 */
1172 if (pstate->p_pre_columnref_hook != NULL)
1173 {
1174 Node *node;
1175
1176 node = pstate->p_pre_columnref_hook(pstate, cref);
1177 if (node != NULL)
1178 return ExpandRowReference(pstate, node, make_target_entry);
1179 }
1180
1181 switch (numnames)
1182 {
1183 case 2:
1184 relname = strVal(linitial(fields));
1185 nsitem = refnameNamespaceItem(pstate, nspname, relname,
1186 cref->location,
1187 &levels_up);
1188 break;
1189 case 3:
1190 nspname = strVal(linitial(fields));
1191 relname = strVal(lsecond(fields));
1192 nsitem = refnameNamespaceItem(pstate, nspname, relname,
1193 cref->location,
1194 &levels_up);
1195 break;
1196 case 4:
1197 {
1198 char *catname = strVal(linitial(fields));
1199
1200 /*
1201 * We check the catalog name and then ignore it.
1202 */
1203 if (strcmp(catname, get_database_name(MyDatabaseId)) != 0)
1204 {
1205 crserr = CRSERR_WRONG_DB;
1206 break;
1207 }
1208 nspname = strVal(lsecond(fields));
1209 relname = strVal(lthird(fields));
1210 nsitem = refnameNamespaceItem(pstate, nspname, relname,
1211 cref->location,
1212 &levels_up);
1213 break;
1214 }
1215 default:
1216 crserr = CRSERR_TOO_MANY;
1217 break;
1218 }
1219
1220 /*
1221 * Now give the PostParseColumnRefHook, if any, a chance. We cheat a
1222 * bit by passing the RangeTblEntry, not a Var, as the planned
1223 * translation. (A single Var wouldn't be strictly correct anyway.
1224 * This convention allows hooks that really care to know what is
1225 * happening. It might be better to pass the nsitem, but we'd have to
1226 * promote that struct to a full-fledged Node type so that callees
1227 * could identify its type.)
1228 */
1229 if (pstate->p_post_columnref_hook != NULL)
1230 {
1231 Node *node;
1232
1233 node = pstate->p_post_columnref_hook(pstate, cref,
1234 (Node *) (nsitem ? nsitem->p_rte : NULL));
1235 if (node != NULL)
1236 {
1237 if (nsitem != NULL)
1238 ereport(ERROR,
1239 (errcode(ERRCODE_AMBIGUOUS_COLUMN),
1240 errmsg("column reference \"%s\" is ambiguous",
1241 NameListToString(cref->fields)),
1242 parser_errposition(pstate, cref->location)));
1243 return ExpandRowReference(pstate, node, make_target_entry);
1244 }
1245 }
1246
1247 /*
1248 * Throw error if no translation found.
1249 */
1250 if (nsitem == NULL)
1251 {
1252 switch (crserr)
1253 {
1254 case CRSERR_NO_RTE:
1255 errorMissingRTE(pstate, makeRangeVar(nspname, relname,
1256 cref->location));
1257 break;
1258 case CRSERR_WRONG_DB:
1259 ereport(ERROR,
1260 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1261 errmsg("cross-database references are not implemented: %s",
1262 NameListToString(cref->fields)),
1263 parser_errposition(pstate, cref->location)));
1264 break;
1265 case CRSERR_TOO_MANY:
1266 ereport(ERROR,
1267 (errcode(ERRCODE_SYNTAX_ERROR),
1268 errmsg("improper qualified name (too many dotted names): %s",
1269 NameListToString(cref->fields)),
1270 parser_errposition(pstate, cref->location)));
1271 break;
1272 }
1273 }
1274
1275 /*
1276 * OK, expand the nsitem into fields.
1277 */
1278 return ExpandSingleTable(pstate, nsitem, levels_up, cref->location,
1279 make_target_entry);
1280 }
1281}
1282
1283/*
1284 * ExpandAllTables()
1285 * Transforms '*' (in the target list) into a list of targetlist entries.
1286 *
1287 * tlist entries are generated for each relation visible for unqualified
1288 * column name access. We do not consider qualified-name-only entries because
1289 * that would include input tables of aliasless JOINs, NEW/OLD pseudo-entries,
1290 * etc.
1291 *
1292 * The referenced relations/columns are marked as requiring SELECT access.
1293 */
1294static List *
1295ExpandAllTables(ParseState *pstate, int location)
1296{
1297 List *target = NIL;
1298 bool found_table = false;
1299 ListCell *l;
1300
1301 foreach(l, pstate->p_namespace)
1302 {
1304
1305 /* Ignore table-only items */
1306 if (!nsitem->p_cols_visible)
1307 continue;
1308 /* Should not have any lateral-only items when parsing targetlist */
1309 Assert(!nsitem->p_lateral_only);
1310 /* Remember we found a p_cols_visible item */
1311 found_table = true;
1312
1313 target = list_concat(target,
1314 expandNSItemAttrs(pstate,
1315 nsitem,
1316 0,
1317 true,
1318 location));
1319 }
1320
1321 /*
1322 * Check for "SELECT *;". We do it this way, rather than checking for
1323 * target == NIL, because we want to allow SELECT * FROM a zero_column
1324 * table.
1325 */
1326 if (!found_table)
1327 ereport(ERROR,
1328 (errcode(ERRCODE_SYNTAX_ERROR),
1329 errmsg("SELECT * with no tables specified is not valid"),
1330 parser_errposition(pstate, location)));
1331
1332 return target;
1333}
1334
1335/*
1336 * ExpandIndirectionStar()
1337 * Transforms foo.* into a list of expressions or targetlist entries.
1338 *
1339 * This handles the case where '*' appears as the last item in A_Indirection.
1340 * The code is shared between the case of foo.* at the top level in a SELECT
1341 * target list (where we want TargetEntry nodes in the result) and foo.* in
1342 * a ROW() or VALUES() construct (where we want just bare expressions).
1343 * For robustness, we use a separate "make_target_entry" flag to control
1344 * this rather than relying on exprKind.
1345 */
1346static List *
1348 bool make_target_entry, ParseExprKind exprKind)
1349{
1350 Node *expr;
1351
1352 /* Strip off the '*' to create a reference to the rowtype object */
1353 ind = copyObject(ind);
1354 ind->indirection = list_truncate(ind->indirection,
1355 list_length(ind->indirection) - 1);
1356
1357 /* And transform that */
1358 expr = transformExpr(pstate, (Node *) ind, exprKind);
1359
1360 /* Expand the rowtype expression into individual fields */
1361 return ExpandRowReference(pstate, expr, make_target_entry);
1362}
1363
1364/*
1365 * ExpandSingleTable()
1366 * Transforms foo.* into a list of expressions or targetlist entries.
1367 *
1368 * This handles the case where foo has been determined to be a simple
1369 * reference to an RTE, so we can just generate Vars for the expressions.
1370 *
1371 * The referenced columns are marked as requiring SELECT access.
1372 */
1373static List *
1375 int sublevels_up, int location, bool make_target_entry)
1376{
1377 if (make_target_entry)
1378 {
1379 /* expandNSItemAttrs handles permissions marking */
1380 return expandNSItemAttrs(pstate, nsitem, sublevels_up, true, location);
1381 }
1382 else
1383 {
1384 RangeTblEntry *rte = nsitem->p_rte;
1385 RTEPermissionInfo *perminfo = nsitem->p_perminfo;
1386 List *vars;
1387 ListCell *l;
1388
1389 vars = expandNSItemVars(pstate, nsitem, sublevels_up, location, NULL);
1390
1391 /*
1392 * Require read access to the table. This is normally redundant with
1393 * the markVarForSelectPriv calls below, but not if the table has zero
1394 * columns. We need not do anything if the nsitem is for a join: its
1395 * component tables will have been marked ACL_SELECT when they were
1396 * added to the rangetable. (This step changes things only for the
1397 * target relation of UPDATE/DELETE, which cannot be under a join.)
1398 */
1399 if (rte->rtekind == RTE_RELATION)
1400 {
1401 Assert(perminfo != NULL);
1402 perminfo->requiredPerms |= ACL_SELECT;
1403 }
1404
1405 /* Require read access to each column */
1406 foreach(l, vars)
1407 {
1408 Var *var = (Var *) lfirst(l);
1409
1410 markVarForSelectPriv(pstate, var);
1411 }
1412
1413 return vars;
1414 }
1415}
1416
1417/*
1418 * ExpandRowReference()
1419 * Transforms foo.* into a list of expressions or targetlist entries.
1420 *
1421 * This handles the case where foo is an arbitrary expression of composite
1422 * type.
1423 */
1424static List *
1426 bool make_target_entry)
1427{
1428 List *result = NIL;
1429 TupleDesc tupleDesc;
1430 int numAttrs;
1431 int i;
1432
1433 /*
1434 * If the rowtype expression is a whole-row Var, we can expand the fields
1435 * as simple Vars. Note: if the RTE is a relation, this case leaves us
1436 * with its RTEPermissionInfo's selectedCols bitmap showing the whole row
1437 * as needing select permission, as well as the individual columns.
1438 * However, we can only get here for weird notations like (table.*).*, so
1439 * it's not worth trying to clean up --- arguably, the permissions marking
1440 * is correct anyway for such cases.
1441 */
1442 if (IsA(expr, Var) &&
1443 ((Var *) expr)->varattno == InvalidAttrNumber)
1444 {
1445 Var *var = (Var *) expr;
1446 ParseNamespaceItem *nsitem;
1447
1448 nsitem = GetNSItemByRangeTablePosn(pstate, var->varno, var->varlevelsup);
1449 return ExpandSingleTable(pstate, nsitem, var->varlevelsup, var->location, make_target_entry);
1450 }
1451
1452 /*
1453 * Otherwise we have to do it the hard way. Our current implementation is
1454 * to generate multiple copies of the expression and do FieldSelects.
1455 * (This can be pretty inefficient if the expression involves nontrivial
1456 * computation :-(.)
1457 *
1458 * Verify it's a composite type, and get the tupdesc.
1459 * get_expr_result_tupdesc() handles this conveniently.
1460 *
1461 * If it's a Var of type RECORD, we have to work even harder: we have to
1462 * find what the Var refers to, and pass that to get_expr_result_tupdesc.
1463 * That task is handled by expandRecordVariable().
1464 */
1465 if (IsA(expr, Var) &&
1466 ((Var *) expr)->vartype == RECORDOID)
1467 tupleDesc = expandRecordVariable(pstate, (Var *) expr, 0);
1468 else
1469 tupleDesc = get_expr_result_tupdesc(expr, false);
1470 Assert(tupleDesc);
1471
1472 /* Generate a list of references to the individual fields */
1473 numAttrs = tupleDesc->natts;
1474 for (i = 0; i < numAttrs; i++)
1475 {
1476 Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
1477 FieldSelect *fselect;
1478
1479 if (att->attisdropped)
1480 continue;
1481
1482 fselect = makeNode(FieldSelect);
1483 fselect->arg = (Expr *) copyObject(expr);
1484 fselect->fieldnum = i + 1;
1485 fselect->resulttype = att->atttypid;
1486 fselect->resulttypmod = att->atttypmod;
1487 /* save attribute's collation for parse_collate.c */
1488 fselect->resultcollid = att->attcollation;
1489
1490 if (make_target_entry)
1491 {
1492 /* add TargetEntry decoration */
1493 TargetEntry *te;
1494
1495 te = makeTargetEntry((Expr *) fselect,
1496 (AttrNumber) pstate->p_next_resno++,
1497 pstrdup(NameStr(att->attname)),
1498 false);
1499 result = lappend(result, te);
1500 }
1501 else
1502 result = lappend(result, fselect);
1503 }
1504
1505 return result;
1506}
1507
1508/*
1509 * expandRecordVariable
1510 * Get the tuple descriptor for a Var of type RECORD, if possible.
1511 *
1512 * Since no actual table or view column is allowed to have type RECORD, such
1513 * a Var must refer to a JOIN or FUNCTION RTE or to a subquery output. We
1514 * drill down to find the ultimate defining expression and attempt to infer
1515 * the tupdesc from it. We ereport if we can't determine the tupdesc.
1516 *
1517 * levelsup is an extra offset to interpret the Var's varlevelsup correctly
1518 * when recursing. Outside callers should pass zero.
1519 */
1521expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
1522{
1523 TupleDesc tupleDesc;
1524 int netlevelsup;
1525 RangeTblEntry *rte;
1527 Node *expr;
1528
1529 /* Check my caller didn't mess up */
1530 Assert(IsA(var, Var));
1531 Assert(var->vartype == RECORDOID);
1532
1533 /*
1534 * Note: it's tempting to use GetNSItemByRangeTablePosn here so that we
1535 * can use expandNSItemVars instead of expandRTE; but that does not work
1536 * for some of the recursion cases below, where we have consed up a
1537 * ParseState that lacks p_namespace data.
1538 */
1539 netlevelsup = var->varlevelsup + levelsup;
1540 rte = GetRTEByRangeTablePosn(pstate, var->varno, netlevelsup);
1541 attnum = var->varattno;
1542
1544 {
1545 /* Whole-row reference to an RTE, so expand the known fields */
1546 List *names,
1547 *vars;
1548 ListCell *lname,
1549 *lvar;
1550 int i;
1551
1552 expandRTE(rte, var->varno, 0, var->varreturningtype,
1553 var->location, false, &names, &vars);
1554
1556 i = 1;
1557 forboth(lname, names, lvar, vars)
1558 {
1559 char *label = strVal(lfirst(lname));
1560 Node *varnode = (Node *) lfirst(lvar);
1561
1562 TupleDescInitEntry(tupleDesc, i,
1563 label,
1564 exprType(varnode),
1565 exprTypmod(varnode),
1566 0);
1567 TupleDescInitEntryCollation(tupleDesc, i,
1568 exprCollation(varnode));
1569 i++;
1570 }
1571 Assert(lname == NULL && lvar == NULL); /* lists same length? */
1572
1573 return tupleDesc;
1574 }
1575
1576 expr = (Node *) var; /* default if we can't drill down */
1577
1578 switch (rte->rtekind)
1579 {
1580 case RTE_RELATION:
1581 case RTE_VALUES:
1583 case RTE_RESULT:
1584
1585 /*
1586 * This case should not occur: a column of a table, values list,
1587 * or ENR shouldn't have type RECORD. Fall through and fail (most
1588 * likely) at the bottom.
1589 */
1590 break;
1591 case RTE_SUBQUERY:
1592 {
1593 /* Subselect-in-FROM: examine sub-select's output expr */
1595 attnum);
1596
1597 if (ste == NULL || ste->resjunk)
1598 elog(ERROR, "subquery %s does not have attribute %d",
1599 rte->eref->aliasname, attnum);
1600 expr = (Node *) ste->expr;
1601 if (IsA(expr, Var))
1602 {
1603 /*
1604 * Recurse into the sub-select to see what its Var refers
1605 * to. We have to build an additional level of ParseState
1606 * to keep in step with varlevelsup in the subselect;
1607 * furthermore, the subquery RTE might be from an outer
1608 * query level, in which case the ParseState for the
1609 * subselect must have that outer level as parent.
1610 */
1611 ParseState mypstate = {0};
1612 Index levelsup;
1613
1614 /* this loop must work, since GetRTEByRangeTablePosn did */
1615 for (levelsup = 0; levelsup < netlevelsup; levelsup++)
1616 pstate = pstate->parentParseState;
1617 mypstate.parentParseState = pstate;
1618 mypstate.p_rtable = rte->subquery->rtable;
1619 /* don't bother filling the rest of the fake pstate */
1620
1621 return expandRecordVariable(&mypstate, (Var *) expr, 0);
1622 }
1623 /* else fall through to inspect the expression */
1624 }
1625 break;
1626 case RTE_JOIN:
1627 /* Join RTE --- recursively inspect the alias variable */
1628 Assert(attnum > 0 && attnum <= list_length(rte->joinaliasvars));
1629 expr = (Node *) list_nth(rte->joinaliasvars, attnum - 1);
1630 Assert(expr != NULL);
1631 /* We intentionally don't strip implicit coercions here */
1632 if (IsA(expr, Var))
1633 return expandRecordVariable(pstate, (Var *) expr, netlevelsup);
1634 /* else fall through to inspect the expression */
1635 break;
1636 case RTE_FUNCTION:
1637
1638 /*
1639 * We couldn't get here unless a function is declared with one of
1640 * its result columns as RECORD, which is not allowed.
1641 */
1642 break;
1643 case RTE_TABLEFUNC:
1644
1645 /*
1646 * Table function cannot have columns with RECORD type.
1647 */
1648 break;
1649 case RTE_CTE:
1650 /* CTE reference: examine subquery's output expr */
1651 if (!rte->self_reference)
1652 {
1653 CommonTableExpr *cte = GetCTEForRTE(pstate, rte, netlevelsup);
1654 TargetEntry *ste;
1655
1657 if (ste == NULL || ste->resjunk)
1658 elog(ERROR, "CTE %s does not have attribute %d",
1659 rte->eref->aliasname, attnum);
1660 expr = (Node *) ste->expr;
1661 if (IsA(expr, Var))
1662 {
1663 /*
1664 * Recurse into the CTE to see what its Var refers to. We
1665 * have to build an additional level of ParseState to keep
1666 * in step with varlevelsup in the CTE; furthermore it
1667 * could be an outer CTE (compare SUBQUERY case above).
1668 */
1669 ParseState mypstate = {0};
1670 Index levelsup;
1671
1672 /* this loop must work, since GetCTEForRTE did */
1673 for (levelsup = 0;
1674 levelsup < rte->ctelevelsup + netlevelsup;
1675 levelsup++)
1676 pstate = pstate->parentParseState;
1677 mypstate.parentParseState = pstate;
1678 mypstate.p_rtable = ((Query *) cte->ctequery)->rtable;
1679 /* don't bother filling the rest of the fake pstate */
1680
1681 return expandRecordVariable(&mypstate, (Var *) expr, 0);
1682 }
1683 /* else fall through to inspect the expression */
1684 }
1685 break;
1686 case RTE_GROUP:
1687
1688 /*
1689 * We couldn't get here: the RTE_GROUP RTE has not been added.
1690 */
1691 break;
1692 }
1693
1694 /*
1695 * We now have an expression we can't expand any more, so see if
1696 * get_expr_result_tupdesc() can do anything with it.
1697 */
1698 return get_expr_result_tupdesc(expr, false);
1699}
1700
1701
1702/*
1703 * FigureColname -
1704 * if the name of the resulting column is not specified in the target
1705 * list, we have to guess a suitable name. The SQL spec provides some
1706 * guidance, but not much...
1707 *
1708 * Note that the argument is the *untransformed* parse tree for the target
1709 * item. This is a shade easier to work with than the transformed tree.
1710 */
1711char *
1713{
1714 char *name = NULL;
1715
1716 (void) FigureColnameInternal(node, &name);
1717 if (name != NULL)
1718 return name;
1719 /* default result if we can't guess anything */
1720 return "?column?";
1721}
1722
1723/*
1724 * FigureIndexColname -
1725 * choose the name for an expression column in an index
1726 *
1727 * This is actually just like FigureColname, except we return NULL if
1728 * we can't pick a good name.
1729 */
1730char *
1732{
1733 char *name = NULL;
1734
1735 (void) FigureColnameInternal(node, &name);
1736 return name;
1737}
1738
1739/*
1740 * FigureColnameInternal -
1741 * internal workhorse for FigureColname
1742 *
1743 * Return value indicates strength of confidence in result:
1744 * 0 - no information
1745 * 1 - second-best name choice
1746 * 2 - good name choice
1747 * The return value is actually only used internally.
1748 * If the result isn't zero, *name is set to the chosen name.
1749 */
1750static int
1752{
1753 int strength = 0;
1754
1755 if (node == NULL)
1756 return strength;
1757
1758 switch (nodeTag(node))
1759 {
1760 case T_ColumnRef:
1761 {
1762 char *fname = NULL;
1763 ListCell *l;
1764
1765 /* find last field name, if any, ignoring "*" */
1766 foreach(l, ((ColumnRef *) node)->fields)
1767 {
1768 Node *i = lfirst(l);
1769
1770 if (IsA(i, String))
1771 fname = strVal(i);
1772 }
1773 if (fname)
1774 {
1775 *name = fname;
1776 return 2;
1777 }
1778 }
1779 break;
1780 case T_A_Indirection:
1781 {
1782 A_Indirection *ind = (A_Indirection *) node;
1783 char *fname = NULL;
1784 ListCell *l;
1785
1786 /* find last field name, if any, ignoring "*" and subscripts */
1787 foreach(l, ind->indirection)
1788 {
1789 Node *i = lfirst(l);
1790
1791 if (IsA(i, String))
1792 fname = strVal(i);
1793 }
1794 if (fname)
1795 {
1796 *name = fname;
1797 return 2;
1798 }
1799 return FigureColnameInternal(ind->arg, name);
1800 }
1801 break;
1802 case T_FuncCall:
1803 *name = strVal(llast(((FuncCall *) node)->funcname));
1804 return 2;
1805 case T_A_Expr:
1806 if (((A_Expr *) node)->kind == AEXPR_NULLIF)
1807 {
1808 /* make nullif() act like a regular function */
1809 *name = "nullif";
1810 return 2;
1811 }
1812 break;
1813 case T_TypeCast:
1814 strength = FigureColnameInternal(((TypeCast *) node)->arg,
1815 name);
1816 if (strength <= 1)
1817 {
1818 if (((TypeCast *) node)->typeName != NULL)
1819 {
1820 *name = strVal(llast(((TypeCast *) node)->typeName->names));
1821 return 1;
1822 }
1823 }
1824 break;
1825 case T_CollateClause:
1826 return FigureColnameInternal(((CollateClause *) node)->arg, name);
1827 case T_GroupingFunc:
1828 /* make GROUPING() act like a regular function */
1829 *name = "grouping";
1830 return 2;
1831 case T_MergeSupportFunc:
1832 /* make MERGE_ACTION() act like a regular function */
1833 *name = "merge_action";
1834 return 2;
1835 case T_SubLink:
1836 switch (((SubLink *) node)->subLinkType)
1837 {
1838 case EXISTS_SUBLINK:
1839 *name = "exists";
1840 return 2;
1841 case ARRAY_SUBLINK:
1842 *name = "array";
1843 return 2;
1844 case EXPR_SUBLINK:
1845 {
1846 /* Get column name of the subquery's single target */
1847 SubLink *sublink = (SubLink *) node;
1848 Query *query = (Query *) sublink->subselect;
1849
1850 /*
1851 * The subquery has probably already been transformed,
1852 * but let's be careful and check that. (The reason
1853 * we can see a transformed subquery here is that
1854 * transformSubLink is lazy and modifies the SubLink
1855 * node in-place.)
1856 */
1857 if (IsA(query, Query))
1858 {
1859 TargetEntry *te = (TargetEntry *) linitial(query->targetList);
1860
1861 if (te->resname)
1862 {
1863 *name = te->resname;
1864 return 2;
1865 }
1866 }
1867 }
1868 break;
1869 /* As with other operator-like nodes, these have no names */
1870 case MULTIEXPR_SUBLINK:
1871 case ALL_SUBLINK:
1872 case ANY_SUBLINK:
1873 case ROWCOMPARE_SUBLINK:
1874 case CTE_SUBLINK:
1875 break;
1876 }
1877 break;
1878 case T_CaseExpr:
1879 strength = FigureColnameInternal((Node *) ((CaseExpr *) node)->defresult,
1880 name);
1881 if (strength <= 1)
1882 {
1883 *name = "case";
1884 return 1;
1885 }
1886 break;
1887 case T_A_ArrayExpr:
1888 /* make ARRAY[] act like a function */
1889 *name = "array";
1890 return 2;
1891 case T_RowExpr:
1892 /* make ROW() act like a function */
1893 *name = "row";
1894 return 2;
1895 case T_CoalesceExpr:
1896 /* make coalesce() act like a regular function */
1897 *name = "coalesce";
1898 return 2;
1899 case T_MinMaxExpr:
1900 /* make greatest/least act like a regular function */
1901 switch (((MinMaxExpr *) node)->op)
1902 {
1903 case IS_GREATEST:
1904 *name = "greatest";
1905 return 2;
1906 case IS_LEAST:
1907 *name = "least";
1908 return 2;
1909 }
1910 break;
1911 case T_SQLValueFunction:
1912 /* make these act like a function or variable */
1913 switch (((SQLValueFunction *) node)->op)
1914 {
1915 case SVFOP_CURRENT_DATE:
1916 *name = "current_date";
1917 return 2;
1918 case SVFOP_CURRENT_TIME:
1920 *name = "current_time";
1921 return 2;
1924 *name = "current_timestamp";
1925 return 2;
1926 case SVFOP_LOCALTIME:
1927 case SVFOP_LOCALTIME_N:
1928 *name = "localtime";
1929 return 2;
1932 *name = "localtimestamp";
1933 return 2;
1934 case SVFOP_CURRENT_ROLE:
1935 *name = "current_role";
1936 return 2;
1937 case SVFOP_CURRENT_USER:
1938 *name = "current_user";
1939 return 2;
1940 case SVFOP_USER:
1941 *name = "user";
1942 return 2;
1943 case SVFOP_SESSION_USER:
1944 *name = "session_user";
1945 return 2;
1947 *name = "current_catalog";
1948 return 2;
1950 *name = "current_schema";
1951 return 2;
1952 }
1953 break;
1954 case T_XmlExpr:
1955 /* make SQL/XML functions act like a regular function */
1956 switch (((XmlExpr *) node)->op)
1957 {
1958 case IS_XMLCONCAT:
1959 *name = "xmlconcat";
1960 return 2;
1961 case IS_XMLELEMENT:
1962 *name = "xmlelement";
1963 return 2;
1964 case IS_XMLFOREST:
1965 *name = "xmlforest";
1966 return 2;
1967 case IS_XMLPARSE:
1968 *name = "xmlparse";
1969 return 2;
1970 case IS_XMLPI:
1971 *name = "xmlpi";
1972 return 2;
1973 case IS_XMLROOT:
1974 *name = "xmlroot";
1975 return 2;
1976 case IS_XMLSERIALIZE:
1977 *name = "xmlserialize";
1978 return 2;
1979 case IS_DOCUMENT:
1980 /* nothing */
1981 break;
1982 }
1983 break;
1984 case T_XmlSerialize:
1985 /* make XMLSERIALIZE act like a regular function */
1986 *name = "xmlserialize";
1987 return 2;
1988 case T_JsonParseExpr:
1989 /* make JSON act like a regular function */
1990 *name = "json";
1991 return 2;
1992 case T_JsonScalarExpr:
1993 /* make JSON_SCALAR act like a regular function */
1994 *name = "json_scalar";
1995 return 2;
1996 case T_JsonSerializeExpr:
1997 /* make JSON_SERIALIZE act like a regular function */
1998 *name = "json_serialize";
1999 return 2;
2000 case T_JsonObjectConstructor:
2001 /* make JSON_OBJECT act like a regular function */
2002 *name = "json_object";
2003 return 2;
2004 case T_JsonArrayConstructor:
2005 case T_JsonArrayQueryConstructor:
2006 /* make JSON_ARRAY act like a regular function */
2007 *name = "json_array";
2008 return 2;
2009 case T_JsonObjectAgg:
2010 /* make JSON_OBJECTAGG act like a regular function */
2011 *name = "json_objectagg";
2012 return 2;
2013 case T_JsonArrayAgg:
2014 /* make JSON_ARRAYAGG act like a regular function */
2015 *name = "json_arrayagg";
2016 return 2;
2017 case T_JsonFuncExpr:
2018 /* make SQL/JSON functions act like a regular function */
2019 switch (((JsonFuncExpr *) node)->op)
2020 {
2021 case JSON_EXISTS_OP:
2022 *name = "json_exists";
2023 return 2;
2024 case JSON_QUERY_OP:
2025 *name = "json_query";
2026 return 2;
2027 case JSON_VALUE_OP:
2028 *name = "json_value";
2029 return 2;
2030 /* JSON_TABLE_OP can't happen here. */
2031 default:
2032 elog(ERROR, "unrecognized JsonExpr op: %d",
2033 (int) ((JsonFuncExpr *) node)->op);
2034 }
2035 break;
2036 default:
2037 break;
2038 }
2039
2040 return strength;
2041}
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:815
#define NameStr(name)
Definition: c.h:752
int32_t int32
Definition: c.h:535
unsigned int Index
Definition: c.h:620
int errhint(const char *fmt,...)
Definition: elog.c:1321
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:150
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
TupleDesc get_expr_result_tupdesc(Node *expr, bool noError)
Definition: funcapi.c:551
Oid MyDatabaseId
Definition: globals.c:94
Assert(PointerIsAligned(start, uint64))
#define funcname
Definition: indent_codes.h:69
int i
Definition: isn.c:77
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
List * lappend(List *list, void *datum)
Definition: list.c:339
List * list_concat(List *list1, const List *list2)
Definition: list.c:561
List * lappend_int(List *list, int datum)
Definition: list.c:357
List * list_truncate(List *list, int new_size)
Definition: list.c:631
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:951
char * get_database_name(Oid dbid)
Definition: lsyscache.c:1259
Oid get_typcollation(Oid typid)
Definition: lsyscache.c:3223
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2705
void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, Oid *typid, int32 *typmod, Oid *collid)
Definition: lsyscache.c:1036
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Definition: makefuncs.c:388
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:473
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:289
char * pstrdup(const char *in)
Definition: mcxt.c:1759
char * NameListToString(const List *names)
Definition: namespace.c:3661
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
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1388
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
#define copyObject(obj)
Definition: nodes.h:232
#define nodeTag(nodeptr)
Definition: nodes.h:139
#define makeNode(_type_)
Definition: nodes.h:161
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Definition: parse_coerce.c:675
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:157
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:78
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:117
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:106
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
Definition: parse_node.c:243
void transformContainerType(Oid *containerType, int32 *containerTypmod)
Definition: parse_node.c:189
ParseExprKind
Definition: parse_node.h:39
@ EXPR_KIND_UPDATE_TARGET
Definition: parse_node.h:57
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_UPDATE_SOURCE
Definition: parse_node.h:56
CommonTableExpr * GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup)
void markVarForSelectPriv(ParseState *pstate, Var *var)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
List * expandNSItemVars(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, VarReturningType returning_type, int location, bool include_dropped, List **colnames, List **colvars)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
Oid attnumTypeId(Relation rd, int attid)
List * expandNSItemAttrs(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, bool require_col_privs, int location)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
int attnameAttNum(Relation rd, const char *attname, bool sysColOK)
TargetEntry * transformTargetEntry(ParseState *pstate, Node *node, Node *expr, ParseExprKind exprKind, char *colname, bool resjunk)
Definition: parse_target.c:74
static List * ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref, bool make_target_entry)
Expr * transformAssignedExpr(ParseState *pstate, Expr *expr, ParseExprKind exprKind, const char *colname, int attrno, List *indirection, int location)
Definition: parse_target.c:454
static int FigureColnameInternal(Node *node, char **name)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
Definition: parse_target.c:219
static void markTargetListOrigin(ParseState *pstate, TargetEntry *tle, Var *var, int levelsup)
Definition: parse_target.c:342
char * FigureColname(Node *node)
static List * ExpandSingleTable(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, bool make_target_entry)
char * FigureIndexColname(Node *node)
static Node * transformAssignmentSubscripts(ParseState *pstate, Node *basenode, const char *targetName, Oid targetTypeId, int32 targetTypMod, Oid targetCollation, List *subscripts, List *indirection, ListCell *next_indirection, Node *rhs, CoercionContext ccontext, int location)
Definition: parse_target.c:905
static List * ExpandRowReference(ParseState *pstate, Node *expr, bool make_target_entry)
Node * transformAssignmentIndirection(ParseState *pstate, Node *basenode, const char *targetName, bool targetIsSubscripting, Oid targetTypeId, int32 targetTypMod, Oid targetCollation, List *indirection, ListCell *indirection_cell, Node *rhs, CoercionContext ccontext, int location)
Definition: parse_target.c:685
void updateTargetListEntry(ParseState *pstate, TargetEntry *tle, char *colname, int attrno, List *indirection, int location)
Definition: parse_target.c:621
List * transformTargetList(ParseState *pstate, List *targetlist, ParseExprKind exprKind)
Definition: parse_target.c:120
void resolveTargetListUnknowns(ParseState *pstate, List *targetlist)
Definition: parse_target.c:287
void markTargetListOrigins(ParseState *pstate, List *targetlist)
Definition: parse_target.c:317
static List * ExpandIndirectionStar(ParseState *pstate, A_Indirection *ind, bool make_target_entry, ParseExprKind exprKind)
static List * ExpandAllTables(ParseState *pstate, int location)
List * checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
TupleDesc expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
Oid typeidTypeRelid(Oid type_id)
Definition: parse_type.c:668
#define GetCTETargetList(cte)
Definition: parsenodes.h:1734
@ AEXPR_NULLIF
Definition: parsenodes.h:334
@ RTE_JOIN
Definition: parsenodes.h:1043
@ RTE_CTE
Definition: parsenodes.h:1047
@ RTE_NAMEDTUPLESTORE
Definition: parsenodes.h:1048
@ RTE_VALUES
Definition: parsenodes.h:1046
@ RTE_SUBQUERY
Definition: parsenodes.h:1042
@ RTE_RESULT
Definition: parsenodes.h:1049
@ RTE_FUNCTION
Definition: parsenodes.h:1044
@ RTE_TABLEFUNC
Definition: parsenodes.h:1045
@ RTE_GROUP
Definition: parsenodes.h:1052
@ RTE_RELATION
Definition: parsenodes.h:1041
struct A_Star A_Star
#define ACL_SELECT
Definition: parsenodes.h:77
int16 attnum
Definition: pg_attribute.h:74
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
void * arg
static char * label
NameData relname
Definition: pg_class.h:38
#define lfirst(lc)
Definition: pg_list.h:172
#define llast(l)
Definition: pg_list.h:198
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:518
#define lthird(l)
Definition: pg_list.h:188
#define list_make1(x1)
Definition: pg_list.h:212
#define for_each_cell(cell, lst, initcell)
Definition: pg_list.h:438
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
#define linitial(l)
Definition: pg_list.h:178
#define lsecond(l)
Definition: pg_list.h:183
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
#define list_make1_int(x1)
Definition: pg_list.h:227
unsigned int Oid
Definition: postgres_ext.h:32
e
Definition: preproc-init.c:82
@ ARRAY_SUBLINK
Definition: primnodes.h:1022
@ ANY_SUBLINK
Definition: primnodes.h:1018
@ MULTIEXPR_SUBLINK
Definition: primnodes.h:1021
@ CTE_SUBLINK
Definition: primnodes.h:1023
@ EXPR_SUBLINK
Definition: primnodes.h:1020
@ ROWCOMPARE_SUBLINK
Definition: primnodes.h:1019
@ ALL_SUBLINK
Definition: primnodes.h:1017
@ EXISTS_SUBLINK
Definition: primnodes.h:1016
@ IS_LEAST
Definition: primnodes.h:1514
@ IS_GREATEST
Definition: primnodes.h:1513
@ SVFOP_CURRENT_CATALOG
Definition: primnodes.h:1560
@ SVFOP_LOCALTIME_N
Definition: primnodes.h:1553
@ SVFOP_CURRENT_TIMESTAMP
Definition: primnodes.h:1550
@ SVFOP_LOCALTIME
Definition: primnodes.h:1552
@ SVFOP_CURRENT_TIMESTAMP_N
Definition: primnodes.h:1551
@ SVFOP_CURRENT_ROLE
Definition: primnodes.h:1556
@ SVFOP_USER
Definition: primnodes.h:1558
@ SVFOP_CURRENT_SCHEMA
Definition: primnodes.h:1561
@ SVFOP_LOCALTIMESTAMP_N
Definition: primnodes.h:1555
@ SVFOP_CURRENT_DATE
Definition: primnodes.h:1547
@ SVFOP_CURRENT_TIME_N
Definition: primnodes.h:1549
@ SVFOP_CURRENT_TIME
Definition: primnodes.h:1548
@ SVFOP_LOCALTIMESTAMP
Definition: primnodes.h:1554
@ SVFOP_CURRENT_USER
Definition: primnodes.h:1557
@ SVFOP_SESSION_USER
Definition: primnodes.h:1559
@ IS_DOCUMENT
Definition: primnodes.h:1598
@ IS_XMLFOREST
Definition: primnodes.h:1593
@ IS_XMLCONCAT
Definition: primnodes.h:1591
@ IS_XMLPI
Definition: primnodes.h:1595
@ IS_XMLPARSE
Definition: primnodes.h:1594
@ IS_XMLSERIALIZE
Definition: primnodes.h:1597
@ IS_XMLROOT
Definition: primnodes.h:1596
@ IS_XMLELEMENT
Definition: primnodes.h:1592
@ JSON_QUERY_OP
Definition: primnodes.h:1814
@ JSON_EXISTS_OP
Definition: primnodes.h:1813
@ JSON_VALUE_OP
Definition: primnodes.h:1815
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:755
CoercionContext
Definition: primnodes.h:732
@ COERCION_ASSIGNMENT
Definition: primnodes.h:734
@ COERCION_IMPLICIT
Definition: primnodes.h:733
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:520
#define RelationGetRelationName(relation)
Definition: rel.h:548
ParseLoc location
Definition: parsenodes.h:311
List * fields
Definition: parsenodes.h:310
AttrNumber fieldnum
Definition: primnodes.h:1148
Expr * arg
Definition: primnodes.h:1147
List * newvals
Definition: primnodes.h:1179
Expr * arg
Definition: primnodes.h:1178
Definition: pg_list.h:54
Definition: nodes.h:135
RangeTblEntry * p_rte
Definition: parse_node.h:295
RTEPermissionInfo * p_perminfo
Definition: parse_node.h:297
ParseState * parentParseState
Definition: parse_node.h:194
ParseNamespaceItem * p_target_nsitem
Definition: parse_node.h:210
ParseExprKind p_expr_kind
Definition: parse_node.h:214
List * p_multiassign_exprs
Definition: parse_node.h:216
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:238
List * p_namespace
Definition: parse_node.h:203
bool p_is_insert
Definition: parse_node.h:212
int p_next_resno
Definition: parse_node.h:215
Relation p_target_relation
Definition: parse_node.h:209
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:239
List * p_rtable
Definition: parse_node.h:196
List * rtable
Definition: parsenodes.h:175
List * targetList
Definition: parsenodes.h:198
AclMode requiredPerms
Definition: parsenodes.h:1320
Index ctelevelsup
Definition: parsenodes.h:1227
Query * subquery
Definition: parsenodes.h:1133
RTEKind rtekind
Definition: parsenodes.h:1076
TupleDesc rd_att
Definition: rel.h:112
Node * val
Definition: parsenodes.h:545
ParseLoc location
Definition: parsenodes.h:546
List * indirection
Definition: parsenodes.h:544
char * name
Definition: parsenodes.h:543
Definition: value.h:64
Expr * refassgnexpr
Definition: primnodes.h:722
Expr * expr
Definition: primnodes.h:2225
AttrNumber resno
Definition: primnodes.h:2227
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
Definition: regcomp.c:282
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:182
void TupleDescInitEntryCollation(TupleDesc desc, AttrNumber attributeNumber, Oid collationid)
Definition: tupdesc.c:1026
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:842
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160
#define strVal(v)
Definition: value.h:82
const char * name