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