PostgreSQL Source Code  git master
parse_expr.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * parse_expr.c
4  * handle expressions in parser
5  *
6  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/parser/parse_expr.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 
16 #include "postgres.h"
17 
18 #include "catalog/pg_type.h"
19 #include "commands/dbcommands.h"
20 #include "miscadmin.h"
21 #include "nodes/makefuncs.h"
22 #include "nodes/nodeFuncs.h"
23 #include "optimizer/optimizer.h"
24 #include "parser/analyze.h"
25 #include "parser/parse_agg.h"
26 #include "parser/parse_clause.h"
27 #include "parser/parse_coerce.h"
28 #include "parser/parse_collate.h"
29 #include "parser/parse_expr.h"
30 #include "parser/parse_func.h"
31 #include "parser/parse_oper.h"
32 #include "parser/parse_relation.h"
33 #include "parser/parse_target.h"
34 #include "parser/parse_type.h"
35 #include "utils/builtins.h"
36 #include "utils/date.h"
37 #include "utils/lsyscache.h"
38 #include "utils/timestamp.h"
39 #include "utils/xml.h"
40 
41 /* GUC parameters */
42 bool Transform_null_equals = false;
43 
44 
45 static Node *transformExprRecurse(ParseState *pstate, Node *expr);
46 static Node *transformParamRef(ParseState *pstate, ParamRef *pref);
47 static Node *transformAExprOp(ParseState *pstate, A_Expr *a);
48 static Node *transformAExprOpAny(ParseState *pstate, A_Expr *a);
49 static Node *transformAExprOpAll(ParseState *pstate, A_Expr *a);
50 static Node *transformAExprDistinct(ParseState *pstate, A_Expr *a);
51 static Node *transformAExprNullIf(ParseState *pstate, A_Expr *a);
52 static Node *transformAExprIn(ParseState *pstate, A_Expr *a);
53 static Node *transformAExprBetween(ParseState *pstate, A_Expr *a);
54 static Node *transformBoolExpr(ParseState *pstate, BoolExpr *a);
55 static Node *transformFuncCall(ParseState *pstate, FuncCall *fn);
56 static Node *transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref);
57 static Node *transformCaseExpr(ParseState *pstate, CaseExpr *c);
58 static Node *transformSubLink(ParseState *pstate, SubLink *sublink);
60  Oid array_type, Oid element_type, int32 typmod);
61 static Node *transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault);
63 static Node *transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m);
64 static Node *transformXmlExpr(ParseState *pstate, XmlExpr *x);
67 static Node *transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr);
68 static Node *transformColumnRef(ParseState *pstate, ColumnRef *cref);
69 static Node *transformWholeRowRef(ParseState *pstate,
70  ParseNamespaceItem *nsitem,
71  int sublevels_up, int location);
73 static Node *transformTypeCast(ParseState *pstate, TypeCast *tc);
75 static Node *make_row_comparison_op(ParseState *pstate, List *opname,
76  List *largs, List *rargs, int location);
77 static Node *make_row_distinct_op(ParseState *pstate, List *opname,
78  RowExpr *lrow, RowExpr *rrow, int location);
79 static Expr *make_distinct_op(ParseState *pstate, List *opname,
80  Node *ltree, Node *rtree, int location);
82  A_Expr *distincta, Node *arg);
83 
84 
85 /*
86  * transformExpr -
87  * Analyze and transform expressions. Type checking and type casting is
88  * done here. This processing converts the raw grammar output into
89  * expression trees with fully determined semantics.
90  */
91 Node *
92 transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
93 {
94  Node *result;
95  ParseExprKind sv_expr_kind;
96 
97  /* Save and restore identity of expression type we're parsing */
98  Assert(exprKind != EXPR_KIND_NONE);
99  sv_expr_kind = pstate->p_expr_kind;
100  pstate->p_expr_kind = exprKind;
101 
102  result = transformExprRecurse(pstate, expr);
103 
104  pstate->p_expr_kind = sv_expr_kind;
105 
106  return result;
107 }
108 
109 static Node *
111 {
112  Node *result;
113 
114  if (expr == NULL)
115  return NULL;
116 
117  /* Guard against stack overflow due to overly complex expressions */
119 
120  switch (nodeTag(expr))
121  {
122  case T_ColumnRef:
123  result = transformColumnRef(pstate, (ColumnRef *) expr);
124  break;
125 
126  case T_ParamRef:
127  result = transformParamRef(pstate, (ParamRef *) expr);
128  break;
129 
130  case T_A_Const:
131  result = (Node *) make_const(pstate, (A_Const *) expr);
132  break;
133 
134  case T_A_Indirection:
135  result = transformIndirection(pstate, (A_Indirection *) expr);
136  break;
137 
138  case T_A_ArrayExpr:
139  result = transformArrayExpr(pstate, (A_ArrayExpr *) expr,
140  InvalidOid, InvalidOid, -1);
141  break;
142 
143  case T_TypeCast:
144  result = transformTypeCast(pstate, (TypeCast *) expr);
145  break;
146 
147  case T_CollateClause:
148  result = transformCollateClause(pstate, (CollateClause *) expr);
149  break;
150 
151  case T_A_Expr:
152  {
153  A_Expr *a = (A_Expr *) expr;
154 
155  switch (a->kind)
156  {
157  case AEXPR_OP:
158  result = transformAExprOp(pstate, a);
159  break;
160  case AEXPR_OP_ANY:
161  result = transformAExprOpAny(pstate, a);
162  break;
163  case AEXPR_OP_ALL:
164  result = transformAExprOpAll(pstate, a);
165  break;
166  case AEXPR_DISTINCT:
167  case AEXPR_NOT_DISTINCT:
168  result = transformAExprDistinct(pstate, a);
169  break;
170  case AEXPR_NULLIF:
171  result = transformAExprNullIf(pstate, a);
172  break;
173  case AEXPR_IN:
174  result = transformAExprIn(pstate, a);
175  break;
176  case AEXPR_LIKE:
177  case AEXPR_ILIKE:
178  case AEXPR_SIMILAR:
179  /* we can transform these just like AEXPR_OP */
180  result = transformAExprOp(pstate, a);
181  break;
182  case AEXPR_BETWEEN:
183  case AEXPR_NOT_BETWEEN:
184  case AEXPR_BETWEEN_SYM:
186  result = transformAExprBetween(pstate, a);
187  break;
188  default:
189  elog(ERROR, "unrecognized A_Expr kind: %d", a->kind);
190  result = NULL; /* keep compiler quiet */
191  break;
192  }
193  break;
194  }
195 
196  case T_BoolExpr:
197  result = transformBoolExpr(pstate, (BoolExpr *) expr);
198  break;
199 
200  case T_FuncCall:
201  result = transformFuncCall(pstate, (FuncCall *) expr);
202  break;
203 
204  case T_MultiAssignRef:
205  result = transformMultiAssignRef(pstate, (MultiAssignRef *) expr);
206  break;
207 
208  case T_GroupingFunc:
209  result = transformGroupingFunc(pstate, (GroupingFunc *) expr);
210  break;
211 
212  case T_NamedArgExpr:
213  {
214  NamedArgExpr *na = (NamedArgExpr *) expr;
215 
216  na->arg = (Expr *) transformExprRecurse(pstate, (Node *) na->arg);
217  result = expr;
218  break;
219  }
220 
221  case T_SubLink:
222  result = transformSubLink(pstate, (SubLink *) expr);
223  break;
224 
225  case T_CaseExpr:
226  result = transformCaseExpr(pstate, (CaseExpr *) expr);
227  break;
228 
229  case T_RowExpr:
230  result = transformRowExpr(pstate, (RowExpr *) expr, false);
231  break;
232 
233  case T_CoalesceExpr:
234  result = transformCoalesceExpr(pstate, (CoalesceExpr *) expr);
235  break;
236 
237  case T_MinMaxExpr:
238  result = transformMinMaxExpr(pstate, (MinMaxExpr *) expr);
239  break;
240 
241  case T_XmlExpr:
242  result = transformXmlExpr(pstate, (XmlExpr *) expr);
243  break;
244 
245  case T_XmlSerialize:
246  result = transformXmlSerialize(pstate, (XmlSerialize *) expr);
247  break;
248 
249  case T_NullTest:
250  {
251  NullTest *n = (NullTest *) expr;
252 
253  n->arg = (Expr *) transformExprRecurse(pstate, (Node *) n->arg);
254  /* the argument can be any type, so don't coerce it */
255  n->argisrow = type_is_rowtype(exprType((Node *) n->arg));
256  result = expr;
257  break;
258  }
259 
260  case T_BooleanTest:
261  result = transformBooleanTest(pstate, (BooleanTest *) expr);
262  break;
263 
264  case T_CurrentOfExpr:
265  result = transformCurrentOfExpr(pstate, (CurrentOfExpr *) expr);
266  break;
267 
268  /*
269  * In all places where DEFAULT is legal, the caller should have
270  * processed it rather than passing it to transformExpr().
271  */
272  case T_SetToDefault:
273  ereport(ERROR,
274  (errcode(ERRCODE_SYNTAX_ERROR),
275  errmsg("DEFAULT is not allowed in this context"),
276  parser_errposition(pstate,
277  ((SetToDefault *) expr)->location)));
278  break;
279 
280  /*
281  * CaseTestExpr doesn't require any processing; it is only
282  * injected into parse trees in a fully-formed state.
283  *
284  * Ordinarily we should not see a Var here, but it is convenient
285  * for transformJoinUsingClause() to create untransformed operator
286  * trees containing already-transformed Vars. The best
287  * alternative would be to deconstruct and reconstruct column
288  * references, which seems expensively pointless. So allow it.
289  */
290  case T_CaseTestExpr:
291  case T_Var:
292  {
293  result = (Node *) expr;
294  break;
295  }
296 
297  default:
298  /* should not reach here */
299  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
300  result = NULL; /* keep compiler quiet */
301  break;
302  }
303 
304  return result;
305 }
306 
307 /*
308  * helper routine for delivering "column does not exist" error message
309  *
310  * (Usually we don't have to work this hard, but the general case of field
311  * selection from an arbitrary node needs it.)
312  */
313 static void
314 unknown_attribute(ParseState *pstate, Node *relref, const char *attname,
315  int location)
316 {
317  RangeTblEntry *rte;
318 
319  if (IsA(relref, Var) &&
320  ((Var *) relref)->varattno == InvalidAttrNumber)
321  {
322  /* Reference the RTE by alias not by actual table name */
323  rte = GetRTEByRangeTablePosn(pstate,
324  ((Var *) relref)->varno,
325  ((Var *) relref)->varlevelsup);
326  ereport(ERROR,
327  (errcode(ERRCODE_UNDEFINED_COLUMN),
328  errmsg("column %s.%s does not exist",
329  rte->eref->aliasname, attname),
330  parser_errposition(pstate, location)));
331  }
332  else
333  {
334  /* Have to do it by reference to the type of the expression */
335  Oid relTypeId = exprType(relref);
336 
337  if (ISCOMPLEX(relTypeId))
338  ereport(ERROR,
339  (errcode(ERRCODE_UNDEFINED_COLUMN),
340  errmsg("column \"%s\" not found in data type %s",
341  attname, format_type_be(relTypeId)),
342  parser_errposition(pstate, location)));
343  else if (relTypeId == RECORDOID)
344  ereport(ERROR,
345  (errcode(ERRCODE_UNDEFINED_COLUMN),
346  errmsg("could not identify column \"%s\" in record data type",
347  attname),
348  parser_errposition(pstate, location)));
349  else
350  ereport(ERROR,
351  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
352  errmsg("column notation .%s applied to type %s, "
353  "which is not a composite type",
354  attname, format_type_be(relTypeId)),
355  parser_errposition(pstate, location)));
356  }
357 }
358 
359 static Node *
361 {
362  Node *last_srf = pstate->p_last_srf;
363  Node *result = transformExprRecurse(pstate, ind->arg);
364  List *subscripts = NIL;
365  int location = exprLocation(result);
366  ListCell *i;
367 
368  /*
369  * We have to split any field-selection operations apart from
370  * subscripting. Adjacent A_Indices nodes have to be treated as a single
371  * multidimensional subscript operation.
372  */
373  foreach(i, ind->indirection)
374  {
375  Node *n = lfirst(i);
376 
377  if (IsA(n, A_Indices))
378  subscripts = lappend(subscripts, n);
379  else if (IsA(n, A_Star))
380  {
381  ereport(ERROR,
382  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
383  errmsg("row expansion via \"*\" is not supported here"),
384  parser_errposition(pstate, location)));
385  }
386  else
387  {
388  Node *newresult;
389 
390  Assert(IsA(n, String));
391 
392  /* process subscripts before this field selection */
393  if (subscripts)
394  result = (Node *) transformContainerSubscripts(pstate,
395  result,
396  exprType(result),
397  exprTypmod(result),
398  subscripts,
399  false);
400  subscripts = NIL;
401 
402  newresult = ParseFuncOrColumn(pstate,
403  list_make1(n),
404  list_make1(result),
405  last_srf,
406  NULL,
407  false,
408  location);
409  if (newresult == NULL)
410  unknown_attribute(pstate, result, strVal(n), location);
411  result = newresult;
412  }
413  }
414  /* process trailing subscripts, if any */
415  if (subscripts)
416  result = (Node *) transformContainerSubscripts(pstate,
417  result,
418  exprType(result),
419  exprTypmod(result),
420  subscripts,
421  false);
422 
423  return result;
424 }
425 
426 /*
427  * Transform a ColumnRef.
428  *
429  * If you find yourself changing this code, see also ExpandColumnRefStar.
430  */
431 static Node *
433 {
434  Node *node = NULL;
435  char *nspname = NULL;
436  char *relname = NULL;
437  char *colname = NULL;
438  ParseNamespaceItem *nsitem;
439  int levels_up;
440  enum
441  {
442  CRERR_NO_COLUMN,
443  CRERR_NO_RTE,
444  CRERR_WRONG_DB,
445  CRERR_TOO_MANY
446  } crerr = CRERR_NO_COLUMN;
447  const char *err;
448 
449  /*
450  * Check to see if the column reference is in an invalid place within the
451  * query. We allow column references in most places, except in default
452  * expressions and partition bound expressions.
453  */
454  err = NULL;
455  switch (pstate->p_expr_kind)
456  {
457  case EXPR_KIND_NONE:
458  Assert(false); /* can't happen */
459  break;
460  case EXPR_KIND_OTHER:
461  case EXPR_KIND_JOIN_ON:
465  case EXPR_KIND_WHERE:
466  case EXPR_KIND_POLICY:
467  case EXPR_KIND_HAVING:
468  case EXPR_KIND_FILTER:
479  case EXPR_KIND_GROUP_BY:
480  case EXPR_KIND_ORDER_BY:
482  case EXPR_KIND_LIMIT:
483  case EXPR_KIND_OFFSET:
484  case EXPR_KIND_RETURNING:
485  case EXPR_KIND_VALUES:
501  /* okay */
502  break;
503 
505  err = _("cannot use column reference in DEFAULT expression");
506  break;
508  err = _("cannot use column reference in partition bound expression");
509  break;
510 
511  /*
512  * There is intentionally no default: case here, so that the
513  * compiler will warn if we add a new ParseExprKind without
514  * extending this switch. If we do see an unrecognized value at
515  * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
516  * which is sane anyway.
517  */
518  }
519  if (err)
520  ereport(ERROR,
521  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
522  errmsg_internal("%s", err),
523  parser_errposition(pstate, cref->location)));
524 
525  /*
526  * Give the PreParseColumnRefHook, if any, first shot. If it returns
527  * non-null then that's all, folks.
528  */
529  if (pstate->p_pre_columnref_hook != NULL)
530  {
531  node = pstate->p_pre_columnref_hook(pstate, cref);
532  if (node != NULL)
533  return node;
534  }
535 
536  /*----------
537  * The allowed syntaxes are:
538  *
539  * A First try to resolve as unqualified column name;
540  * if no luck, try to resolve as unqualified table name (A.*).
541  * A.B A is an unqualified table name; B is either a
542  * column or function name (trying column name first).
543  * A.B.C schema A, table B, col or func name C.
544  * A.B.C.D catalog A, schema B, table C, col or func D.
545  * A.* A is an unqualified table name; means whole-row value.
546  * A.B.* whole-row value of table B in schema A.
547  * A.B.C.* whole-row value of table C in schema B in catalog A.
548  *
549  * We do not need to cope with bare "*"; that will only be accepted by
550  * the grammar at the top level of a SELECT list, and transformTargetList
551  * will take care of it before it ever gets here. Also, "A.*" etc will
552  * be expanded by transformTargetList if they appear at SELECT top level,
553  * so here we are only going to see them as function or operator inputs.
554  *
555  * Currently, if a catalog name is given then it must equal the current
556  * database name; we check it here and then discard it.
557  *----------
558  */
559  switch (list_length(cref->fields))
560  {
561  case 1:
562  {
563  Node *field1 = (Node *) linitial(cref->fields);
564 
565  colname = strVal(field1);
566 
567  /* Try to identify as an unqualified column */
568  node = colNameToVar(pstate, colname, false, cref->location);
569 
570  if (node == NULL)
571  {
572  /*
573  * Not known as a column of any range-table entry.
574  *
575  * Try to find the name as a relation. Note that only
576  * relations already entered into the rangetable will be
577  * recognized.
578  *
579  * This is a hack for backwards compatibility with
580  * PostQUEL-inspired syntax. The preferred form now is
581  * "rel.*".
582  */
583  nsitem = refnameNamespaceItem(pstate, NULL, colname,
584  cref->location,
585  &levels_up);
586  if (nsitem)
587  node = transformWholeRowRef(pstate, nsitem, levels_up,
588  cref->location);
589  }
590  break;
591  }
592  case 2:
593  {
594  Node *field1 = (Node *) linitial(cref->fields);
595  Node *field2 = (Node *) lsecond(cref->fields);
596 
597  relname = strVal(field1);
598 
599  /* Locate the referenced nsitem */
600  nsitem = refnameNamespaceItem(pstate, nspname, relname,
601  cref->location,
602  &levels_up);
603  if (nsitem == NULL)
604  {
605  crerr = CRERR_NO_RTE;
606  break;
607  }
608 
609  /* Whole-row reference? */
610  if (IsA(field2, A_Star))
611  {
612  node = transformWholeRowRef(pstate, nsitem, levels_up,
613  cref->location);
614  break;
615  }
616 
617  colname = strVal(field2);
618 
619  /* Try to identify as a column of the nsitem */
620  node = scanNSItemForColumn(pstate, nsitem, levels_up, colname,
621  cref->location);
622  if (node == NULL)
623  {
624  /* Try it as a function call on the whole row */
625  node = transformWholeRowRef(pstate, nsitem, levels_up,
626  cref->location);
627  node = ParseFuncOrColumn(pstate,
628  list_make1(makeString(colname)),
629  list_make1(node),
630  pstate->p_last_srf,
631  NULL,
632  false,
633  cref->location);
634  }
635  break;
636  }
637  case 3:
638  {
639  Node *field1 = (Node *) linitial(cref->fields);
640  Node *field2 = (Node *) lsecond(cref->fields);
641  Node *field3 = (Node *) lthird(cref->fields);
642 
643  nspname = strVal(field1);
644  relname = strVal(field2);
645 
646  /* Locate the referenced nsitem */
647  nsitem = refnameNamespaceItem(pstate, nspname, relname,
648  cref->location,
649  &levels_up);
650  if (nsitem == NULL)
651  {
652  crerr = CRERR_NO_RTE;
653  break;
654  }
655 
656  /* Whole-row reference? */
657  if (IsA(field3, A_Star))
658  {
659  node = transformWholeRowRef(pstate, nsitem, levels_up,
660  cref->location);
661  break;
662  }
663 
664  colname = strVal(field3);
665 
666  /* Try to identify as a column of the nsitem */
667  node = scanNSItemForColumn(pstate, nsitem, levels_up, colname,
668  cref->location);
669  if (node == NULL)
670  {
671  /* Try it as a function call on the whole row */
672  node = transformWholeRowRef(pstate, nsitem, levels_up,
673  cref->location);
674  node = ParseFuncOrColumn(pstate,
675  list_make1(makeString(colname)),
676  list_make1(node),
677  pstate->p_last_srf,
678  NULL,
679  false,
680  cref->location);
681  }
682  break;
683  }
684  case 4:
685  {
686  Node *field1 = (Node *) linitial(cref->fields);
687  Node *field2 = (Node *) lsecond(cref->fields);
688  Node *field3 = (Node *) lthird(cref->fields);
689  Node *field4 = (Node *) lfourth(cref->fields);
690  char *catname;
691 
692  catname = strVal(field1);
693  nspname = strVal(field2);
694  relname = strVal(field3);
695 
696  /*
697  * We check the catalog name and then ignore it.
698  */
699  if (strcmp(catname, get_database_name(MyDatabaseId)) != 0)
700  {
701  crerr = CRERR_WRONG_DB;
702  break;
703  }
704 
705  /* Locate the referenced nsitem */
706  nsitem = refnameNamespaceItem(pstate, nspname, relname,
707  cref->location,
708  &levels_up);
709  if (nsitem == NULL)
710  {
711  crerr = CRERR_NO_RTE;
712  break;
713  }
714 
715  /* Whole-row reference? */
716  if (IsA(field4, A_Star))
717  {
718  node = transformWholeRowRef(pstate, nsitem, levels_up,
719  cref->location);
720  break;
721  }
722 
723  colname = strVal(field4);
724 
725  /* Try to identify as a column of the nsitem */
726  node = scanNSItemForColumn(pstate, nsitem, levels_up, colname,
727  cref->location);
728  if (node == NULL)
729  {
730  /* Try it as a function call on the whole row */
731  node = transformWholeRowRef(pstate, nsitem, levels_up,
732  cref->location);
733  node = ParseFuncOrColumn(pstate,
734  list_make1(makeString(colname)),
735  list_make1(node),
736  pstate->p_last_srf,
737  NULL,
738  false,
739  cref->location);
740  }
741  break;
742  }
743  default:
744  crerr = CRERR_TOO_MANY; /* too many dotted names */
745  break;
746  }
747 
748  /*
749  * Now give the PostParseColumnRefHook, if any, a chance. We pass the
750  * translation-so-far so that it can throw an error if it wishes in the
751  * case that it has a conflicting interpretation of the ColumnRef. (If it
752  * just translates anyway, we'll throw an error, because we can't undo
753  * whatever effects the preceding steps may have had on the pstate.) If it
754  * returns NULL, use the standard translation, or throw a suitable error
755  * if there is none.
756  */
757  if (pstate->p_post_columnref_hook != NULL)
758  {
759  Node *hookresult;
760 
761  hookresult = pstate->p_post_columnref_hook(pstate, cref, node);
762  if (node == NULL)
763  node = hookresult;
764  else if (hookresult != NULL)
765  ereport(ERROR,
766  (errcode(ERRCODE_AMBIGUOUS_COLUMN),
767  errmsg("column reference \"%s\" is ambiguous",
768  NameListToString(cref->fields)),
769  parser_errposition(pstate, cref->location)));
770  }
771 
772  /*
773  * Throw error if no translation found.
774  */
775  if (node == NULL)
776  {
777  switch (crerr)
778  {
779  case CRERR_NO_COLUMN:
780  errorMissingColumn(pstate, relname, colname, cref->location);
781  break;
782  case CRERR_NO_RTE:
783  errorMissingRTE(pstate, makeRangeVar(nspname, relname,
784  cref->location));
785  break;
786  case CRERR_WRONG_DB:
787  ereport(ERROR,
788  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
789  errmsg("cross-database references are not implemented: %s",
790  NameListToString(cref->fields)),
791  parser_errposition(pstate, cref->location)));
792  break;
793  case CRERR_TOO_MANY:
794  ereport(ERROR,
795  (errcode(ERRCODE_SYNTAX_ERROR),
796  errmsg("improper qualified name (too many dotted names): %s",
797  NameListToString(cref->fields)),
798  parser_errposition(pstate, cref->location)));
799  break;
800  }
801  }
802 
803  return node;
804 }
805 
806 static Node *
808 {
809  Node *result;
810 
811  /*
812  * The core parser knows nothing about Params. If a hook is supplied,
813  * call it. If not, or if the hook returns NULL, throw a generic error.
814  */
815  if (pstate->p_paramref_hook != NULL)
816  result = pstate->p_paramref_hook(pstate, pref);
817  else
818  result = NULL;
819 
820  if (result == NULL)
821  ereport(ERROR,
822  (errcode(ERRCODE_UNDEFINED_PARAMETER),
823  errmsg("there is no parameter $%d", pref->number),
824  parser_errposition(pstate, pref->location)));
825 
826  return result;
827 }
828 
829 /* Test whether an a_expr is a plain NULL constant or not */
830 static bool
832 {
833  if (arg && IsA(arg, A_Const))
834  {
835  A_Const *con = (A_Const *) arg;
836 
837  if (con->isnull)
838  return true;
839  }
840  return false;
841 }
842 
843 static Node *
845 {
846  Node *lexpr = a->lexpr;
847  Node *rexpr = a->rexpr;
848  Node *result;
849 
850  /*
851  * Special-case "foo = NULL" and "NULL = foo" for compatibility with
852  * standards-broken products (like Microsoft's). Turn these into IS NULL
853  * exprs. (If either side is a CaseTestExpr, then the expression was
854  * generated internally from a CASE-WHEN expression, and
855  * transform_null_equals does not apply.)
856  */
857  if (Transform_null_equals &&
858  list_length(a->name) == 1 &&
859  strcmp(strVal(linitial(a->name)), "=") == 0 &&
860  (exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)) &&
861  (!IsA(lexpr, CaseTestExpr) && !IsA(rexpr, CaseTestExpr)))
862  {
863  NullTest *n = makeNode(NullTest);
864 
865  n->nulltesttype = IS_NULL;
866  n->location = a->location;
867 
868  if (exprIsNullConstant(lexpr))
869  n->arg = (Expr *) rexpr;
870  else
871  n->arg = (Expr *) lexpr;
872 
873  result = transformExprRecurse(pstate, (Node *) n);
874  }
875  else if (lexpr && IsA(lexpr, RowExpr) &&
876  rexpr && IsA(rexpr, SubLink) &&
877  ((SubLink *) rexpr)->subLinkType == EXPR_SUBLINK)
878  {
879  /*
880  * Convert "row op subselect" into a ROWCOMPARE sublink. Formerly the
881  * grammar did this, but now that a row construct is allowed anywhere
882  * in expressions, it's easier to do it here.
883  */
884  SubLink *s = (SubLink *) rexpr;
885 
887  s->testexpr = lexpr;
888  s->operName = a->name;
889  s->location = a->location;
890  result = transformExprRecurse(pstate, (Node *) s);
891  }
892  else if (lexpr && IsA(lexpr, RowExpr) &&
893  rexpr && IsA(rexpr, RowExpr))
894  {
895  /* ROW() op ROW() is handled specially */
896  lexpr = transformExprRecurse(pstate, lexpr);
897  rexpr = transformExprRecurse(pstate, rexpr);
898 
899  result = make_row_comparison_op(pstate,
900  a->name,
901  castNode(RowExpr, lexpr)->args,
902  castNode(RowExpr, rexpr)->args,
903  a->location);
904  }
905  else
906  {
907  /* Ordinary scalar operator */
908  Node *last_srf = pstate->p_last_srf;
909 
910  lexpr = transformExprRecurse(pstate, lexpr);
911  rexpr = transformExprRecurse(pstate, rexpr);
912 
913  result = (Node *) make_op(pstate,
914  a->name,
915  lexpr,
916  rexpr,
917  last_srf,
918  a->location);
919  }
920 
921  return result;
922 }
923 
924 static Node *
926 {
927  Node *lexpr = transformExprRecurse(pstate, a->lexpr);
928  Node *rexpr = transformExprRecurse(pstate, a->rexpr);
929 
930  return (Node *) make_scalar_array_op(pstate,
931  a->name,
932  true,
933  lexpr,
934  rexpr,
935  a->location);
936 }
937 
938 static Node *
940 {
941  Node *lexpr = transformExprRecurse(pstate, a->lexpr);
942  Node *rexpr = transformExprRecurse(pstate, a->rexpr);
943 
944  return (Node *) make_scalar_array_op(pstate,
945  a->name,
946  false,
947  lexpr,
948  rexpr,
949  a->location);
950 }
951 
952 static Node *
954 {
955  Node *lexpr = a->lexpr;
956  Node *rexpr = a->rexpr;
957  Node *result;
958 
959  /*
960  * If either input is an undecorated NULL literal, transform to a NullTest
961  * on the other input. That's simpler to process than a full DistinctExpr,
962  * and it avoids needing to require that the datatype have an = operator.
963  */
964  if (exprIsNullConstant(rexpr))
965  return make_nulltest_from_distinct(pstate, a, lexpr);
966  if (exprIsNullConstant(lexpr))
967  return make_nulltest_from_distinct(pstate, a, rexpr);
968 
969  lexpr = transformExprRecurse(pstate, lexpr);
970  rexpr = transformExprRecurse(pstate, rexpr);
971 
972  if (lexpr && IsA(lexpr, RowExpr) &&
973  rexpr && IsA(rexpr, RowExpr))
974  {
975  /* ROW() op ROW() is handled specially */
976  result = make_row_distinct_op(pstate, a->name,
977  (RowExpr *) lexpr,
978  (RowExpr *) rexpr,
979  a->location);
980  }
981  else
982  {
983  /* Ordinary scalar operator */
984  result = (Node *) make_distinct_op(pstate,
985  a->name,
986  lexpr,
987  rexpr,
988  a->location);
989  }
990 
991  /*
992  * If it's NOT DISTINCT, we first build a DistinctExpr and then stick a
993  * NOT on top.
994  */
995  if (a->kind == AEXPR_NOT_DISTINCT)
996  result = (Node *) makeBoolExpr(NOT_EXPR,
997  list_make1(result),
998  a->location);
999 
1000  return result;
1001 }
1002 
1003 static Node *
1005 {
1006  Node *lexpr = transformExprRecurse(pstate, a->lexpr);
1007  Node *rexpr = transformExprRecurse(pstate, a->rexpr);
1008  OpExpr *result;
1009 
1010  result = (OpExpr *) make_op(pstate,
1011  a->name,
1012  lexpr,
1013  rexpr,
1014  pstate->p_last_srf,
1015  a->location);
1016 
1017  /*
1018  * The comparison operator itself should yield boolean ...
1019  */
1020  if (result->opresulttype != BOOLOID)
1021  ereport(ERROR,
1022  (errcode(ERRCODE_DATATYPE_MISMATCH),
1023  errmsg("NULLIF requires = operator to yield boolean"),
1024  parser_errposition(pstate, a->location)));
1025  if (result->opretset)
1026  ereport(ERROR,
1027  (errcode(ERRCODE_DATATYPE_MISMATCH),
1028  /* translator: %s is name of a SQL construct, eg NULLIF */
1029  errmsg("%s must not return a set", "NULLIF"),
1030  parser_errposition(pstate, a->location)));
1031 
1032  /*
1033  * ... but the NullIfExpr will yield the first operand's type.
1034  */
1035  result->opresulttype = exprType((Node *) linitial(result->args));
1036 
1037  /*
1038  * We rely on NullIfExpr and OpExpr being the same struct
1039  */
1040  NodeSetTag(result, T_NullIfExpr);
1041 
1042  return (Node *) result;
1043 }
1044 
1045 static Node *
1047 {
1048  Node *result = NULL;
1049  Node *lexpr;
1050  List *rexprs;
1051  List *rvars;
1052  List *rnonvars;
1053  bool useOr;
1054  ListCell *l;
1055 
1056  /*
1057  * If the operator is <>, combine with AND not OR.
1058  */
1059  if (strcmp(strVal(linitial(a->name)), "<>") == 0)
1060  useOr = false;
1061  else
1062  useOr = true;
1063 
1064  /*
1065  * We try to generate a ScalarArrayOpExpr from IN/NOT IN, but this is only
1066  * possible if there is a suitable array type available. If not, we fall
1067  * back to a boolean condition tree with multiple copies of the lefthand
1068  * expression. Also, any IN-list items that contain Vars are handled as
1069  * separate boolean conditions, because that gives the planner more scope
1070  * for optimization on such clauses.
1071  *
1072  * First step: transform all the inputs, and detect whether any contain
1073  * Vars.
1074  */
1075  lexpr = transformExprRecurse(pstate, a->lexpr);
1076  rexprs = rvars = rnonvars = NIL;
1077  foreach(l, (List *) a->rexpr)
1078  {
1079  Node *rexpr = transformExprRecurse(pstate, lfirst(l));
1080 
1081  rexprs = lappend(rexprs, rexpr);
1082  if (contain_vars_of_level(rexpr, 0))
1083  rvars = lappend(rvars, rexpr);
1084  else
1085  rnonvars = lappend(rnonvars, rexpr);
1086  }
1087 
1088  /*
1089  * ScalarArrayOpExpr is only going to be useful if there's more than one
1090  * non-Var righthand item.
1091  */
1092  if (list_length(rnonvars) > 1)
1093  {
1094  List *allexprs;
1095  Oid scalar_type;
1096  Oid array_type;
1097 
1098  /*
1099  * Try to select a common type for the array elements. Note that
1100  * since the LHS' type is first in the list, it will be preferred when
1101  * there is doubt (eg, when all the RHS items are unknown literals).
1102  *
1103  * Note: use list_concat here not lcons, to avoid damaging rnonvars.
1104  */
1105  allexprs = list_concat(list_make1(lexpr), rnonvars);
1106  scalar_type = select_common_type(pstate, allexprs, NULL, NULL);
1107 
1108  /* We have to verify that the selected type actually works */
1109  if (OidIsValid(scalar_type) &&
1110  !verify_common_type(scalar_type, allexprs))
1111  scalar_type = InvalidOid;
1112 
1113  /*
1114  * Do we have an array type to use? Aside from the case where there
1115  * isn't one, we don't risk using ScalarArrayOpExpr when the common
1116  * type is RECORD, because the RowExpr comparison logic below can cope
1117  * with some cases of non-identical row types.
1118  */
1119  if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
1120  array_type = get_array_type(scalar_type);
1121  else
1122  array_type = InvalidOid;
1123  if (array_type != InvalidOid)
1124  {
1125  /*
1126  * OK: coerce all the right-hand non-Var inputs to the common type
1127  * and build an ArrayExpr for them.
1128  */
1129  List *aexprs;
1130  ArrayExpr *newa;
1131 
1132  aexprs = NIL;
1133  foreach(l, rnonvars)
1134  {
1135  Node *rexpr = (Node *) lfirst(l);
1136 
1137  rexpr = coerce_to_common_type(pstate, rexpr,
1138  scalar_type,
1139  "IN");
1140  aexprs = lappend(aexprs, rexpr);
1141  }
1142  newa = makeNode(ArrayExpr);
1143  newa->array_typeid = array_type;
1144  /* array_collid will be set by parse_collate.c */
1145  newa->element_typeid = scalar_type;
1146  newa->elements = aexprs;
1147  newa->multidims = false;
1148  newa->location = -1;
1149 
1150  result = (Node *) make_scalar_array_op(pstate,
1151  a->name,
1152  useOr,
1153  lexpr,
1154  (Node *) newa,
1155  a->location);
1156 
1157  /* Consider only the Vars (if any) in the loop below */
1158  rexprs = rvars;
1159  }
1160  }
1161 
1162  /*
1163  * Must do it the hard way, ie, with a boolean expression tree.
1164  */
1165  foreach(l, rexprs)
1166  {
1167  Node *rexpr = (Node *) lfirst(l);
1168  Node *cmp;
1169 
1170  if (IsA(lexpr, RowExpr) &&
1171  IsA(rexpr, RowExpr))
1172  {
1173  /* ROW() op ROW() is handled specially */
1174  cmp = make_row_comparison_op(pstate,
1175  a->name,
1176  copyObject(((RowExpr *) lexpr)->args),
1177  ((RowExpr *) rexpr)->args,
1178  a->location);
1179  }
1180  else
1181  {
1182  /* Ordinary scalar operator */
1183  cmp = (Node *) make_op(pstate,
1184  a->name,
1185  copyObject(lexpr),
1186  rexpr,
1187  pstate->p_last_srf,
1188  a->location);
1189  }
1190 
1191  cmp = coerce_to_boolean(pstate, cmp, "IN");
1192  if (result == NULL)
1193  result = cmp;
1194  else
1195  result = (Node *) makeBoolExpr(useOr ? OR_EXPR : AND_EXPR,
1196  list_make2(result, cmp),
1197  a->location);
1198  }
1199 
1200  return result;
1201 }
1202 
1203 static Node *
1205 {
1206  Node *aexpr;
1207  Node *bexpr;
1208  Node *cexpr;
1209  Node *result;
1210  Node *sub1;
1211  Node *sub2;
1212  List *args;
1213 
1214  /* Deconstruct A_Expr into three subexprs */
1215  aexpr = a->lexpr;
1216  args = castNode(List, a->rexpr);
1217  Assert(list_length(args) == 2);
1218  bexpr = (Node *) linitial(args);
1219  cexpr = (Node *) lsecond(args);
1220 
1221  /*
1222  * Build the equivalent comparison expression. Make copies of
1223  * multiply-referenced subexpressions for safety. (XXX this is really
1224  * wrong since it results in multiple runtime evaluations of what may be
1225  * volatile expressions ...)
1226  *
1227  * Ideally we would not use hard-wired operators here but instead use
1228  * opclasses. However, mixed data types and other issues make this
1229  * difficult:
1230  * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
1231  */
1232  switch (a->kind)
1233  {
1234  case AEXPR_BETWEEN:
1236  aexpr, bexpr,
1237  a->location),
1238  makeSimpleA_Expr(AEXPR_OP, "<=",
1239  copyObject(aexpr), cexpr,
1240  a->location));
1241  result = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1242  break;
1243  case AEXPR_NOT_BETWEEN:
1245  aexpr, bexpr,
1246  a->location),
1248  copyObject(aexpr), cexpr,
1249  a->location));
1250  result = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1251  break;
1252  case AEXPR_BETWEEN_SYM:
1254  aexpr, bexpr,
1255  a->location),
1256  makeSimpleA_Expr(AEXPR_OP, "<=",
1257  copyObject(aexpr), cexpr,
1258  a->location));
1259  sub1 = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1261  copyObject(aexpr), copyObject(cexpr),
1262  a->location),
1263  makeSimpleA_Expr(AEXPR_OP, "<=",
1264  copyObject(aexpr), copyObject(bexpr),
1265  a->location));
1266  sub2 = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1267  args = list_make2(sub1, sub2);
1268  result = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1269  break;
1270  case AEXPR_NOT_BETWEEN_SYM:
1272  aexpr, bexpr,
1273  a->location),
1275  copyObject(aexpr), cexpr,
1276  a->location));
1277  sub1 = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1279  copyObject(aexpr), copyObject(cexpr),
1280  a->location),
1282  copyObject(aexpr), copyObject(bexpr),
1283  a->location));
1284  sub2 = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1285  args = list_make2(sub1, sub2);
1286  result = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1287  break;
1288  default:
1289  elog(ERROR, "unrecognized A_Expr kind: %d", a->kind);
1290  result = NULL; /* keep compiler quiet */
1291  break;
1292  }
1293 
1294  return transformExprRecurse(pstate, result);
1295 }
1296 
1297 static Node *
1299 {
1300  List *args = NIL;
1301  const char *opname;
1302  ListCell *lc;
1303 
1304  switch (a->boolop)
1305  {
1306  case AND_EXPR:
1307  opname = "AND";
1308  break;
1309  case OR_EXPR:
1310  opname = "OR";
1311  break;
1312  case NOT_EXPR:
1313  opname = "NOT";
1314  break;
1315  default:
1316  elog(ERROR, "unrecognized boolop: %d", (int) a->boolop);
1317  opname = NULL; /* keep compiler quiet */
1318  break;
1319  }
1320 
1321  foreach(lc, a->args)
1322  {
1323  Node *arg = (Node *) lfirst(lc);
1324 
1325  arg = transformExprRecurse(pstate, arg);
1326  arg = coerce_to_boolean(pstate, arg, opname);
1327  args = lappend(args, arg);
1328  }
1329 
1330  return (Node *) makeBoolExpr(a->boolop, args, a->location);
1331 }
1332 
1333 static Node *
1335 {
1336  Node *last_srf = pstate->p_last_srf;
1337  List *targs;
1338  ListCell *args;
1339 
1340  /* Transform the list of arguments ... */
1341  targs = NIL;
1342  foreach(args, fn->args)
1343  {
1344  targs = lappend(targs, transformExprRecurse(pstate,
1345  (Node *) lfirst(args)));
1346  }
1347 
1348  /*
1349  * When WITHIN GROUP is used, we treat its ORDER BY expressions as
1350  * additional arguments to the function, for purposes of function lookup
1351  * and argument type coercion. So, transform each such expression and add
1352  * them to the targs list. We don't explicitly mark where each argument
1353  * came from, but ParseFuncOrColumn can tell what's what by reference to
1354  * list_length(fn->agg_order).
1355  */
1356  if (fn->agg_within_group)
1357  {
1358  Assert(fn->agg_order != NIL);
1359  foreach(args, fn->agg_order)
1360  {
1361  SortBy *arg = (SortBy *) lfirst(args);
1362 
1363  targs = lappend(targs, transformExpr(pstate, arg->node,
1365  }
1366  }
1367 
1368  /* ... and hand off to ParseFuncOrColumn */
1369  return ParseFuncOrColumn(pstate,
1370  fn->funcname,
1371  targs,
1372  last_srf,
1373  fn,
1374  false,
1375  fn->location);
1376 }
1377 
1378 static Node *
1380 {
1381  SubLink *sublink;
1382  RowExpr *rexpr;
1383  Query *qtree;
1384  TargetEntry *tle;
1385 
1386  /* We should only see this in first-stage processing of UPDATE tlists */
1388 
1389  /* We only need to transform the source if this is the first column */
1390  if (maref->colno == 1)
1391  {
1392  /*
1393  * For now, we only allow EXPR SubLinks and RowExprs as the source of
1394  * an UPDATE multiassignment. This is sufficient to cover interesting
1395  * cases; at worst, someone would have to write (SELECT * FROM expr)
1396  * to expand a composite-returning expression of another form.
1397  */
1398  if (IsA(maref->source, SubLink) &&
1399  ((SubLink *) maref->source)->subLinkType == EXPR_SUBLINK)
1400  {
1401  /* Relabel it as a MULTIEXPR_SUBLINK */
1402  sublink = (SubLink *) maref->source;
1403  sublink->subLinkType = MULTIEXPR_SUBLINK;
1404  /* And transform it */
1405  sublink = (SubLink *) transformExprRecurse(pstate,
1406  (Node *) sublink);
1407 
1408  qtree = castNode(Query, sublink->subselect);
1409 
1410  /* Check subquery returns required number of columns */
1411  if (count_nonjunk_tlist_entries(qtree->targetList) != maref->ncolumns)
1412  ereport(ERROR,
1413  (errcode(ERRCODE_SYNTAX_ERROR),
1414  errmsg("number of columns does not match number of values"),
1415  parser_errposition(pstate, sublink->location)));
1416 
1417  /*
1418  * Build a resjunk tlist item containing the MULTIEXPR SubLink,
1419  * and add it to pstate->p_multiassign_exprs, whence it will later
1420  * get appended to the completed targetlist. We needn't worry
1421  * about selecting a resno for it; transformUpdateStmt will do
1422  * that.
1423  */
1424  tle = makeTargetEntry((Expr *) sublink, 0, NULL, true);
1426  tle);
1427 
1428  /*
1429  * Assign a unique-within-this-targetlist ID to the MULTIEXPR
1430  * SubLink. We can just use its position in the
1431  * p_multiassign_exprs list.
1432  */
1433  sublink->subLinkId = list_length(pstate->p_multiassign_exprs);
1434  }
1435  else if (IsA(maref->source, RowExpr))
1436  {
1437  /* Transform the RowExpr, allowing SetToDefault items */
1438  rexpr = (RowExpr *) transformRowExpr(pstate,
1439  (RowExpr *) maref->source,
1440  true);
1441 
1442  /* Check it returns required number of columns */
1443  if (list_length(rexpr->args) != maref->ncolumns)
1444  ereport(ERROR,
1445  (errcode(ERRCODE_SYNTAX_ERROR),
1446  errmsg("number of columns does not match number of values"),
1447  parser_errposition(pstate, rexpr->location)));
1448 
1449  /*
1450  * Temporarily append it to p_multiassign_exprs, so we can get it
1451  * back when we come back here for additional columns.
1452  */
1453  tle = makeTargetEntry((Expr *) rexpr, 0, NULL, true);
1455  tle);
1456  }
1457  else
1458  ereport(ERROR,
1459  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1460  errmsg("source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"),
1461  parser_errposition(pstate, exprLocation(maref->source))));
1462  }
1463  else
1464  {
1465  /*
1466  * Second or later column in a multiassignment. Re-fetch the
1467  * transformed SubLink or RowExpr, which we assume is still the last
1468  * entry in p_multiassign_exprs.
1469  */
1470  Assert(pstate->p_multiassign_exprs != NIL);
1471  tle = (TargetEntry *) llast(pstate->p_multiassign_exprs);
1472  }
1473 
1474  /*
1475  * Emit the appropriate output expression for the current column
1476  */
1477  if (IsA(tle->expr, SubLink))
1478  {
1479  Param *param;
1480 
1481  sublink = (SubLink *) tle->expr;
1482  Assert(sublink->subLinkType == MULTIEXPR_SUBLINK);
1483  qtree = castNode(Query, sublink->subselect);
1484 
1485  /* Build a Param representing the current subquery output column */
1486  tle = (TargetEntry *) list_nth(qtree->targetList, maref->colno - 1);
1487  Assert(!tle->resjunk);
1488 
1489  param = makeNode(Param);
1490  param->paramkind = PARAM_MULTIEXPR;
1491  param->paramid = (sublink->subLinkId << 16) | maref->colno;
1492  param->paramtype = exprType((Node *) tle->expr);
1493  param->paramtypmod = exprTypmod((Node *) tle->expr);
1494  param->paramcollid = exprCollation((Node *) tle->expr);
1495  param->location = exprLocation((Node *) tle->expr);
1496 
1497  return (Node *) param;
1498  }
1499 
1500  if (IsA(tle->expr, RowExpr))
1501  {
1502  Node *result;
1503 
1504  rexpr = (RowExpr *) tle->expr;
1505 
1506  /* Just extract and return the next element of the RowExpr */
1507  result = (Node *) list_nth(rexpr->args, maref->colno - 1);
1508 
1509  /*
1510  * If we're at the last column, delete the RowExpr from
1511  * p_multiassign_exprs; we don't need it anymore, and don't want it in
1512  * the finished UPDATE tlist. We assume this is still the last entry
1513  * in p_multiassign_exprs.
1514  */
1515  if (maref->colno == maref->ncolumns)
1516  pstate->p_multiassign_exprs =
1518 
1519  return result;
1520  }
1521 
1522  elog(ERROR, "unexpected expr type in multiassign list");
1523  return NULL; /* keep compiler quiet */
1524 }
1525 
1526 static Node *
1528 {
1529  CaseExpr *newc = makeNode(CaseExpr);
1530  Node *last_srf = pstate->p_last_srf;
1531  Node *arg;
1532  CaseTestExpr *placeholder;
1533  List *newargs;
1534  List *resultexprs;
1535  ListCell *l;
1536  Node *defresult;
1537  Oid ptype;
1538 
1539  /* transform the test expression, if any */
1540  arg = transformExprRecurse(pstate, (Node *) c->arg);
1541 
1542  /* generate placeholder for test expression */
1543  if (arg)
1544  {
1545  /*
1546  * If test expression is an untyped literal, force it to text. We have
1547  * to do something now because we won't be able to do this coercion on
1548  * the placeholder. This is not as flexible as what was done in 7.4
1549  * and before, but it's good enough to handle the sort of silly coding
1550  * commonly seen.
1551  */
1552  if (exprType(arg) == UNKNOWNOID)
1553  arg = coerce_to_common_type(pstate, arg, TEXTOID, "CASE");
1554 
1555  /*
1556  * Run collation assignment on the test expression so that we know
1557  * what collation to mark the placeholder with. In principle we could
1558  * leave it to parse_collate.c to do that later, but propagating the
1559  * result to the CaseTestExpr would be unnecessarily complicated.
1560  */
1561  assign_expr_collations(pstate, arg);
1562 
1563  placeholder = makeNode(CaseTestExpr);
1564  placeholder->typeId = exprType(arg);
1565  placeholder->typeMod = exprTypmod(arg);
1566  placeholder->collation = exprCollation(arg);
1567  }
1568  else
1569  placeholder = NULL;
1570 
1571  newc->arg = (Expr *) arg;
1572 
1573  /* transform the list of arguments */
1574  newargs = NIL;
1575  resultexprs = NIL;
1576  foreach(l, c->args)
1577  {
1578  CaseWhen *w = lfirst_node(CaseWhen, l);
1579  CaseWhen *neww = makeNode(CaseWhen);
1580  Node *warg;
1581 
1582  warg = (Node *) w->expr;
1583  if (placeholder)
1584  {
1585  /* shorthand form was specified, so expand... */
1586  warg = (Node *) makeSimpleA_Expr(AEXPR_OP, "=",
1587  (Node *) placeholder,
1588  warg,
1589  w->location);
1590  }
1591  neww->expr = (Expr *) transformExprRecurse(pstate, warg);
1592 
1593  neww->expr = (Expr *) coerce_to_boolean(pstate,
1594  (Node *) neww->expr,
1595  "CASE/WHEN");
1596 
1597  warg = (Node *) w->result;
1598  neww->result = (Expr *) transformExprRecurse(pstate, warg);
1599  neww->location = w->location;
1600 
1601  newargs = lappend(newargs, neww);
1602  resultexprs = lappend(resultexprs, neww->result);
1603  }
1604 
1605  newc->args = newargs;
1606 
1607  /* transform the default clause */
1608  defresult = (Node *) c->defresult;
1609  if (defresult == NULL)
1610  {
1611  A_Const *n = makeNode(A_Const);
1612 
1613  n->isnull = true;
1614  n->location = -1;
1615  defresult = (Node *) n;
1616  }
1617  newc->defresult = (Expr *) transformExprRecurse(pstate, defresult);
1618 
1619  /*
1620  * Note: default result is considered the most significant type in
1621  * determining preferred type. This is how the code worked before, but it
1622  * seems a little bogus to me --- tgl
1623  */
1624  resultexprs = lcons(newc->defresult, resultexprs);
1625 
1626  ptype = select_common_type(pstate, resultexprs, "CASE", NULL);
1627  Assert(OidIsValid(ptype));
1628  newc->casetype = ptype;
1629  /* casecollid will be set by parse_collate.c */
1630 
1631  /* Convert default result clause, if necessary */
1632  newc->defresult = (Expr *)
1633  coerce_to_common_type(pstate,
1634  (Node *) newc->defresult,
1635  ptype,
1636  "CASE/ELSE");
1637 
1638  /* Convert when-clause results, if necessary */
1639  foreach(l, newc->args)
1640  {
1641  CaseWhen *w = (CaseWhen *) lfirst(l);
1642 
1643  w->result = (Expr *)
1644  coerce_to_common_type(pstate,
1645  (Node *) w->result,
1646  ptype,
1647  "CASE/WHEN");
1648  }
1649 
1650  /* if any subexpression contained a SRF, complain */
1651  if (pstate->p_last_srf != last_srf)
1652  ereport(ERROR,
1653  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1654  /* translator: %s is name of a SQL construct, eg GROUP BY */
1655  errmsg("set-returning functions are not allowed in %s",
1656  "CASE"),
1657  errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
1658  parser_errposition(pstate,
1659  exprLocation(pstate->p_last_srf))));
1660 
1661  newc->location = c->location;
1662 
1663  return (Node *) newc;
1664 }
1665 
1666 static Node *
1668 {
1669  Node *result = (Node *) sublink;
1670  Query *qtree;
1671  const char *err;
1672 
1673  /*
1674  * Check to see if the sublink is in an invalid place within the query. We
1675  * allow sublinks everywhere in SELECT/INSERT/UPDATE/DELETE/MERGE, but
1676  * generally not in utility statements.
1677  */
1678  err = NULL;
1679  switch (pstate->p_expr_kind)
1680  {
1681  case EXPR_KIND_NONE:
1682  Assert(false); /* can't happen */
1683  break;
1684  case EXPR_KIND_OTHER:
1685  /* Accept sublink here; caller must throw error if wanted */
1686  break;
1687  case EXPR_KIND_JOIN_ON:
1688  case EXPR_KIND_JOIN_USING:
1691  case EXPR_KIND_WHERE:
1692  case EXPR_KIND_POLICY:
1693  case EXPR_KIND_HAVING:
1694  case EXPR_KIND_FILTER:
1704  case EXPR_KIND_MERGE_WHEN:
1705  case EXPR_KIND_GROUP_BY:
1706  case EXPR_KIND_ORDER_BY:
1707  case EXPR_KIND_DISTINCT_ON:
1708  case EXPR_KIND_LIMIT:
1709  case EXPR_KIND_OFFSET:
1710  case EXPR_KIND_RETURNING:
1711  case EXPR_KIND_VALUES:
1713  case EXPR_KIND_CYCLE_MARK:
1714  /* okay */
1715  break;
1718  err = _("cannot use subquery in check constraint");
1719  break;
1722  err = _("cannot use subquery in DEFAULT expression");
1723  break;
1725  err = _("cannot use subquery in index expression");
1726  break;
1728  err = _("cannot use subquery in index predicate");
1729  break;
1731  err = _("cannot use subquery in statistics expression");
1732  break;
1734  err = _("cannot use subquery in transform expression");
1735  break;
1737  err = _("cannot use subquery in EXECUTE parameter");
1738  break;
1740  err = _("cannot use subquery in trigger WHEN condition");
1741  break;
1743  err = _("cannot use subquery in partition bound");
1744  break;
1746  err = _("cannot use subquery in partition key expression");
1747  break;
1749  err = _("cannot use subquery in CALL argument");
1750  break;
1751  case EXPR_KIND_COPY_WHERE:
1752  err = _("cannot use subquery in COPY FROM WHERE condition");
1753  break;
1755  err = _("cannot use subquery in column generation expression");
1756  break;
1757 
1758  /*
1759  * There is intentionally no default: case here, so that the
1760  * compiler will warn if we add a new ParseExprKind without
1761  * extending this switch. If we do see an unrecognized value at
1762  * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
1763  * which is sane anyway.
1764  */
1765  }
1766  if (err)
1767  ereport(ERROR,
1768  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1769  errmsg_internal("%s", err),
1770  parser_errposition(pstate, sublink->location)));
1771 
1772  pstate->p_hasSubLinks = true;
1773 
1774  /*
1775  * OK, let's transform the sub-SELECT.
1776  */
1777  qtree = parse_sub_analyze(sublink->subselect, pstate, NULL, false, true);
1778 
1779  /*
1780  * Check that we got a SELECT. Anything else should be impossible given
1781  * restrictions of the grammar, but check anyway.
1782  */
1783  if (!IsA(qtree, Query) ||
1784  qtree->commandType != CMD_SELECT)
1785  elog(ERROR, "unexpected non-SELECT command in SubLink");
1786 
1787  sublink->subselect = (Node *) qtree;
1788 
1789  if (sublink->subLinkType == EXISTS_SUBLINK)
1790  {
1791  /*
1792  * EXISTS needs no test expression or combining operator. These fields
1793  * should be null already, but make sure.
1794  */
1795  sublink->testexpr = NULL;
1796  sublink->operName = NIL;
1797  }
1798  else if (sublink->subLinkType == EXPR_SUBLINK ||
1799  sublink->subLinkType == ARRAY_SUBLINK)
1800  {
1801  /*
1802  * Make sure the subselect delivers a single column (ignoring resjunk
1803  * targets).
1804  */
1805  if (count_nonjunk_tlist_entries(qtree->targetList) != 1)
1806  ereport(ERROR,
1807  (errcode(ERRCODE_SYNTAX_ERROR),
1808  errmsg("subquery must return only one column"),
1809  parser_errposition(pstate, sublink->location)));
1810 
1811  /*
1812  * EXPR and ARRAY need no test expression or combining operator. These
1813  * fields should be null already, but make sure.
1814  */
1815  sublink->testexpr = NULL;
1816  sublink->operName = NIL;
1817  }
1818  else if (sublink->subLinkType == MULTIEXPR_SUBLINK)
1819  {
1820  /* Same as EXPR case, except no restriction on number of columns */
1821  sublink->testexpr = NULL;
1822  sublink->operName = NIL;
1823  }
1824  else
1825  {
1826  /* ALL, ANY, or ROWCOMPARE: generate row-comparing expression */
1827  Node *lefthand;
1828  List *left_list;
1829  List *right_list;
1830  ListCell *l;
1831 
1832  /*
1833  * If the source was "x IN (select)", convert to "x = ANY (select)".
1834  */
1835  if (sublink->operName == NIL)
1836  sublink->operName = list_make1(makeString("="));
1837 
1838  /*
1839  * Transform lefthand expression, and convert to a list
1840  */
1841  lefthand = transformExprRecurse(pstate, sublink->testexpr);
1842  if (lefthand && IsA(lefthand, RowExpr))
1843  left_list = ((RowExpr *) lefthand)->args;
1844  else
1845  left_list = list_make1(lefthand);
1846 
1847  /*
1848  * Build a list of PARAM_SUBLINK nodes representing the output columns
1849  * of the subquery.
1850  */
1851  right_list = NIL;
1852  foreach(l, qtree->targetList)
1853  {
1854  TargetEntry *tent = (TargetEntry *) lfirst(l);
1855  Param *param;
1856 
1857  if (tent->resjunk)
1858  continue;
1859 
1860  param = makeNode(Param);
1861  param->paramkind = PARAM_SUBLINK;
1862  param->paramid = tent->resno;
1863  param->paramtype = exprType((Node *) tent->expr);
1864  param->paramtypmod = exprTypmod((Node *) tent->expr);
1865  param->paramcollid = exprCollation((Node *) tent->expr);
1866  param->location = -1;
1867 
1868  right_list = lappend(right_list, param);
1869  }
1870 
1871  /*
1872  * We could rely on make_row_comparison_op to complain if the list
1873  * lengths differ, but we prefer to generate a more specific error
1874  * message.
1875  */
1876  if (list_length(left_list) < list_length(right_list))
1877  ereport(ERROR,
1878  (errcode(ERRCODE_SYNTAX_ERROR),
1879  errmsg("subquery has too many columns"),
1880  parser_errposition(pstate, sublink->location)));
1881  if (list_length(left_list) > list_length(right_list))
1882  ereport(ERROR,
1883  (errcode(ERRCODE_SYNTAX_ERROR),
1884  errmsg("subquery has too few columns"),
1885  parser_errposition(pstate, sublink->location)));
1886 
1887  /*
1888  * Identify the combining operator(s) and generate a suitable
1889  * row-comparison expression.
1890  */
1891  sublink->testexpr = make_row_comparison_op(pstate,
1892  sublink->operName,
1893  left_list,
1894  right_list,
1895  sublink->location);
1896  }
1897 
1898  return result;
1899 }
1900 
1901 /*
1902  * transformArrayExpr
1903  *
1904  * If the caller specifies the target type, the resulting array will
1905  * be of exactly that type. Otherwise we try to infer a common type
1906  * for the elements using select_common_type().
1907  */
1908 static Node *
1910  Oid array_type, Oid element_type, int32 typmod)
1911 {
1912  ArrayExpr *newa = makeNode(ArrayExpr);
1913  List *newelems = NIL;
1914  List *newcoercedelems = NIL;
1915  ListCell *element;
1916  Oid coerce_type;
1917  bool coerce_hard;
1918 
1919  /*
1920  * Transform the element expressions
1921  *
1922  * Assume that the array is one-dimensional unless we find an array-type
1923  * element expression.
1924  */
1925  newa->multidims = false;
1926  foreach(element, a->elements)
1927  {
1928  Node *e = (Node *) lfirst(element);
1929  Node *newe;
1930 
1931  /*
1932  * If an element is itself an A_ArrayExpr, recurse directly so that we
1933  * can pass down any target type we were given.
1934  */
1935  if (IsA(e, A_ArrayExpr))
1936  {
1937  newe = transformArrayExpr(pstate,
1938  (A_ArrayExpr *) e,
1939  array_type,
1940  element_type,
1941  typmod);
1942  /* we certainly have an array here */
1943  Assert(array_type == InvalidOid || array_type == exprType(newe));
1944  newa->multidims = true;
1945  }
1946  else
1947  {
1948  newe = transformExprRecurse(pstate, e);
1949 
1950  /*
1951  * Check for sub-array expressions, if we haven't already found
1952  * one.
1953  */
1954  if (!newa->multidims && type_is_array(exprType(newe)))
1955  newa->multidims = true;
1956  }
1957 
1958  newelems = lappend(newelems, newe);
1959  }
1960 
1961  /*
1962  * Select a target type for the elements.
1963  *
1964  * If we haven't been given a target array type, we must try to deduce a
1965  * common type based on the types of the individual elements present.
1966  */
1967  if (OidIsValid(array_type))
1968  {
1969  /* Caller must ensure array_type matches element_type */
1970  Assert(OidIsValid(element_type));
1971  coerce_type = (newa->multidims ? array_type : element_type);
1972  coerce_hard = true;
1973  }
1974  else
1975  {
1976  /* Can't handle an empty array without a target type */
1977  if (newelems == NIL)
1978  ereport(ERROR,
1979  (errcode(ERRCODE_INDETERMINATE_DATATYPE),
1980  errmsg("cannot determine type of empty array"),
1981  errhint("Explicitly cast to the desired type, "
1982  "for example ARRAY[]::integer[]."),
1983  parser_errposition(pstate, a->location)));
1984 
1985  /* Select a common type for the elements */
1986  coerce_type = select_common_type(pstate, newelems, "ARRAY", NULL);
1987 
1988  if (newa->multidims)
1989  {
1990  array_type = coerce_type;
1991  element_type = get_element_type(array_type);
1992  if (!OidIsValid(element_type))
1993  ereport(ERROR,
1994  (errcode(ERRCODE_UNDEFINED_OBJECT),
1995  errmsg("could not find element type for data type %s",
1996  format_type_be(array_type)),
1997  parser_errposition(pstate, a->location)));
1998  }
1999  else
2000  {
2001  element_type = coerce_type;
2002  array_type = get_array_type(element_type);
2003  if (!OidIsValid(array_type))
2004  ereport(ERROR,
2005  (errcode(ERRCODE_UNDEFINED_OBJECT),
2006  errmsg("could not find array type for data type %s",
2007  format_type_be(element_type)),
2008  parser_errposition(pstate, a->location)));
2009  }
2010  coerce_hard = false;
2011  }
2012 
2013  /*
2014  * Coerce elements to target type
2015  *
2016  * If the array has been explicitly cast, then the elements are in turn
2017  * explicitly coerced.
2018  *
2019  * If the array's type was merely derived from the common type of its
2020  * elements, then the elements are implicitly coerced to the common type.
2021  * This is consistent with other uses of select_common_type().
2022  */
2023  foreach(element, newelems)
2024  {
2025  Node *e = (Node *) lfirst(element);
2026  Node *newe;
2027 
2028  if (coerce_hard)
2029  {
2030  newe = coerce_to_target_type(pstate, e,
2031  exprType(e),
2032  coerce_type,
2033  typmod,
2036  -1);
2037  if (newe == NULL)
2038  ereport(ERROR,
2039  (errcode(ERRCODE_CANNOT_COERCE),
2040  errmsg("cannot cast type %s to %s",
2043  parser_errposition(pstate, exprLocation(e))));
2044  }
2045  else
2046  newe = coerce_to_common_type(pstate, e,
2047  coerce_type,
2048  "ARRAY");
2049  newcoercedelems = lappend(newcoercedelems, newe);
2050  }
2051 
2052  newa->array_typeid = array_type;
2053  /* array_collid will be set by parse_collate.c */
2054  newa->element_typeid = element_type;
2055  newa->elements = newcoercedelems;
2056  newa->location = a->location;
2057 
2058  return (Node *) newa;
2059 }
2060 
2061 static Node *
2062 transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
2063 {
2064  RowExpr *newr;
2065  char fname[16];
2066  int fnum;
2067 
2068  newr = makeNode(RowExpr);
2069 
2070  /* Transform the field expressions */
2071  newr->args = transformExpressionList(pstate, r->args,
2072  pstate->p_expr_kind, allowDefault);
2073 
2074  /* Disallow more columns than will fit in a tuple */
2076  ereport(ERROR,
2077  (errcode(ERRCODE_TOO_MANY_COLUMNS),
2078  errmsg("ROW expressions can have at most %d entries",
2080  parser_errposition(pstate, r->location)));
2081 
2082  /* Barring later casting, we consider the type RECORD */
2083  newr->row_typeid = RECORDOID;
2084  newr->row_format = COERCE_IMPLICIT_CAST;
2085 
2086  /* ROW() has anonymous columns, so invent some field names */
2087  newr->colnames = NIL;
2088  for (fnum = 1; fnum <= list_length(newr->args); fnum++)
2089  {
2090  snprintf(fname, sizeof(fname), "f%d", fnum);
2091  newr->colnames = lappend(newr->colnames, makeString(pstrdup(fname)));
2092  }
2093 
2094  newr->location = r->location;
2095 
2096  return (Node *) newr;
2097 }
2098 
2099 static Node *
2101 {
2103  Node *last_srf = pstate->p_last_srf;
2104  List *newargs = NIL;
2105  List *newcoercedargs = NIL;
2106  ListCell *args;
2107 
2108  foreach(args, c->args)
2109  {
2110  Node *e = (Node *) lfirst(args);
2111  Node *newe;
2112 
2113  newe = transformExprRecurse(pstate, e);
2114  newargs = lappend(newargs, newe);
2115  }
2116 
2117  newc->coalescetype = select_common_type(pstate, newargs, "COALESCE", NULL);
2118  /* coalescecollid will be set by parse_collate.c */
2119 
2120  /* Convert arguments if necessary */
2121  foreach(args, newargs)
2122  {
2123  Node *e = (Node *) lfirst(args);
2124  Node *newe;
2125 
2126  newe = coerce_to_common_type(pstate, e,
2127  newc->coalescetype,
2128  "COALESCE");
2129  newcoercedargs = lappend(newcoercedargs, newe);
2130  }
2131 
2132  /* if any subexpression contained a SRF, complain */
2133  if (pstate->p_last_srf != last_srf)
2134  ereport(ERROR,
2135  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2136  /* translator: %s is name of a SQL construct, eg GROUP BY */
2137  errmsg("set-returning functions are not allowed in %s",
2138  "COALESCE"),
2139  errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
2140  parser_errposition(pstate,
2141  exprLocation(pstate->p_last_srf))));
2142 
2143  newc->args = newcoercedargs;
2144  newc->location = c->location;
2145  return (Node *) newc;
2146 }
2147 
2148 static Node *
2150 {
2151  MinMaxExpr *newm = makeNode(MinMaxExpr);
2152  List *newargs = NIL;
2153  List *newcoercedargs = NIL;
2154  const char *funcname = (m->op == IS_GREATEST) ? "GREATEST" : "LEAST";
2155  ListCell *args;
2156 
2157  newm->op = m->op;
2158  foreach(args, m->args)
2159  {
2160  Node *e = (Node *) lfirst(args);
2161  Node *newe;
2162 
2163  newe = transformExprRecurse(pstate, e);
2164  newargs = lappend(newargs, newe);
2165  }
2166 
2167  newm->minmaxtype = select_common_type(pstate, newargs, funcname, NULL);
2168  /* minmaxcollid and inputcollid will be set by parse_collate.c */
2169 
2170  /* Convert arguments if necessary */
2171  foreach(args, newargs)
2172  {
2173  Node *e = (Node *) lfirst(args);
2174  Node *newe;
2175 
2176  newe = coerce_to_common_type(pstate, e,
2177  newm->minmaxtype,
2178  funcname);
2179  newcoercedargs = lappend(newcoercedargs, newe);
2180  }
2181 
2182  newm->args = newcoercedargs;
2183  newm->location = m->location;
2184  return (Node *) newm;
2185 }
2186 
2187 static Node *
2189 {
2190  XmlExpr *newx;
2191  ListCell *lc;
2192  int i;
2193 
2194  newx = makeNode(XmlExpr);
2195  newx->op = x->op;
2196  if (x->name)
2197  newx->name = map_sql_identifier_to_xml_name(x->name, false, false);
2198  else
2199  newx->name = NULL;
2200  newx->xmloption = x->xmloption;
2201  newx->type = XMLOID; /* this just marks the node as transformed */
2202  newx->typmod = -1;
2203  newx->location = x->location;
2204 
2205  /*
2206  * gram.y built the named args as a list of ResTarget. Transform each,
2207  * and break the names out as a separate list.
2208  */
2209  newx->named_args = NIL;
2210  newx->arg_names = NIL;
2211 
2212  foreach(lc, x->named_args)
2213  {
2214  ResTarget *r = lfirst_node(ResTarget, lc);
2215  Node *expr;
2216  char *argname;
2217 
2218  expr = transformExprRecurse(pstate, r->val);
2219 
2220  if (r->name)
2221  argname = map_sql_identifier_to_xml_name(r->name, false, false);
2222  else if (IsA(r->val, ColumnRef))
2224  true, false);
2225  else
2226  {
2227  ereport(ERROR,
2228  (errcode(ERRCODE_SYNTAX_ERROR),
2229  x->op == IS_XMLELEMENT
2230  ? errmsg("unnamed XML attribute value must be a column reference")
2231  : errmsg("unnamed XML element value must be a column reference"),
2232  parser_errposition(pstate, r->location)));
2233  argname = NULL; /* keep compiler quiet */
2234  }
2235 
2236  /* reject duplicate argnames in XMLELEMENT only */
2237  if (x->op == IS_XMLELEMENT)
2238  {
2239  ListCell *lc2;
2240 
2241  foreach(lc2, newx->arg_names)
2242  {
2243  if (strcmp(argname, strVal(lfirst(lc2))) == 0)
2244  ereport(ERROR,
2245  (errcode(ERRCODE_SYNTAX_ERROR),
2246  errmsg("XML attribute name \"%s\" appears more than once",
2247  argname),
2248  parser_errposition(pstate, r->location)));
2249  }
2250  }
2251 
2252  newx->named_args = lappend(newx->named_args, expr);
2253  newx->arg_names = lappend(newx->arg_names, makeString(argname));
2254  }
2255 
2256  /* The other arguments are of varying types depending on the function */
2257  newx->args = NIL;
2258  i = 0;
2259  foreach(lc, x->args)
2260  {
2261  Node *e = (Node *) lfirst(lc);
2262  Node *newe;
2263 
2264  newe = transformExprRecurse(pstate, e);
2265  switch (x->op)
2266  {
2267  case IS_XMLCONCAT:
2268  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2269  "XMLCONCAT");
2270  break;
2271  case IS_XMLELEMENT:
2272  /* no coercion necessary */
2273  break;
2274  case IS_XMLFOREST:
2275  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2276  "XMLFOREST");
2277  break;
2278  case IS_XMLPARSE:
2279  if (i == 0)
2280  newe = coerce_to_specific_type(pstate, newe, TEXTOID,
2281  "XMLPARSE");
2282  else
2283  newe = coerce_to_boolean(pstate, newe, "XMLPARSE");
2284  break;
2285  case IS_XMLPI:
2286  newe = coerce_to_specific_type(pstate, newe, TEXTOID,
2287  "XMLPI");
2288  break;
2289  case IS_XMLROOT:
2290  if (i == 0)
2291  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2292  "XMLROOT");
2293  else if (i == 1)
2294  newe = coerce_to_specific_type(pstate, newe, TEXTOID,
2295  "XMLROOT");
2296  else
2297  newe = coerce_to_specific_type(pstate, newe, INT4OID,
2298  "XMLROOT");
2299  break;
2300  case IS_XMLSERIALIZE:
2301  /* not handled here */
2302  Assert(false);
2303  break;
2304  case IS_DOCUMENT:
2305  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2306  "IS DOCUMENT");
2307  break;
2308  }
2309  newx->args = lappend(newx->args, newe);
2310  i++;
2311  }
2312 
2313  return (Node *) newx;
2314 }
2315 
2316 static Node *
2318 {
2319  Node *result;
2320  XmlExpr *xexpr;
2321  Oid targetType;
2322  int32 targetTypmod;
2323 
2324  xexpr = makeNode(XmlExpr);
2325  xexpr->op = IS_XMLSERIALIZE;
2326  xexpr->args = list_make1(coerce_to_specific_type(pstate,
2327  transformExprRecurse(pstate, xs->expr),
2328  XMLOID,
2329  "XMLSERIALIZE"));
2330 
2331  typenameTypeIdAndMod(pstate, xs->typeName, &targetType, &targetTypmod);
2332 
2333  xexpr->xmloption = xs->xmloption;
2334  xexpr->indent = xs->indent;
2335  xexpr->location = xs->location;
2336  /* We actually only need these to be able to parse back the expression. */
2337  xexpr->type = targetType;
2338  xexpr->typmod = targetTypmod;
2339 
2340  /*
2341  * The actual target type is determined this way. SQL allows char and
2342  * varchar as target types. We allow anything that can be cast implicitly
2343  * from text. This way, user-defined text-like data types automatically
2344  * fit in.
2345  */
2346  result = coerce_to_target_type(pstate, (Node *) xexpr,
2347  TEXTOID, targetType, targetTypmod,
2350  -1);
2351  if (result == NULL)
2352  ereport(ERROR,
2353  (errcode(ERRCODE_CANNOT_COERCE),
2354  errmsg("cannot cast XMLSERIALIZE result to %s",
2355  format_type_be(targetType)),
2356  parser_errposition(pstate, xexpr->location)));
2357  return result;
2358 }
2359 
2360 static Node *
2362 {
2363  const char *clausename;
2364 
2365  switch (b->booltesttype)
2366  {
2367  case IS_TRUE:
2368  clausename = "IS TRUE";
2369  break;
2370  case IS_NOT_TRUE:
2371  clausename = "IS NOT TRUE";
2372  break;
2373  case IS_FALSE:
2374  clausename = "IS FALSE";
2375  break;
2376  case IS_NOT_FALSE:
2377  clausename = "IS NOT FALSE";
2378  break;
2379  case IS_UNKNOWN:
2380  clausename = "IS UNKNOWN";
2381  break;
2382  case IS_NOT_UNKNOWN:
2383  clausename = "IS NOT UNKNOWN";
2384  break;
2385  default:
2386  elog(ERROR, "unrecognized booltesttype: %d",
2387  (int) b->booltesttype);
2388  clausename = NULL; /* keep compiler quiet */
2389  }
2390 
2391  b->arg = (Expr *) transformExprRecurse(pstate, (Node *) b->arg);
2392 
2393  b->arg = (Expr *) coerce_to_boolean(pstate,
2394  (Node *) b->arg,
2395  clausename);
2396 
2397  return (Node *) b;
2398 }
2399 
2400 static Node *
2402 {
2403  /* CURRENT OF can only appear at top level of UPDATE/DELETE */
2404  Assert(pstate->p_target_nsitem != NULL);
2405  cexpr->cvarno = pstate->p_target_nsitem->p_rtindex;
2406 
2407  /*
2408  * Check to see if the cursor name matches a parameter of type REFCURSOR.
2409  * If so, replace the raw name reference with a parameter reference. (This
2410  * is a hack for the convenience of plpgsql.)
2411  */
2412  if (cexpr->cursor_name != NULL) /* in case already transformed */
2413  {
2414  ColumnRef *cref = makeNode(ColumnRef);
2415  Node *node = NULL;
2416 
2417  /* Build an unqualified ColumnRef with the given name */
2418  cref->fields = list_make1(makeString(cexpr->cursor_name));
2419  cref->location = -1;
2420 
2421  /* See if there is a translation available from a parser hook */
2422  if (pstate->p_pre_columnref_hook != NULL)
2423  node = pstate->p_pre_columnref_hook(pstate, cref);
2424  if (node == NULL && pstate->p_post_columnref_hook != NULL)
2425  node = pstate->p_post_columnref_hook(pstate, cref, NULL);
2426 
2427  /*
2428  * XXX Should we throw an error if we get a translation that isn't a
2429  * refcursor Param? For now it seems best to silently ignore false
2430  * matches.
2431  */
2432  if (node != NULL && IsA(node, Param))
2433  {
2434  Param *p = (Param *) node;
2435 
2436  if (p->paramkind == PARAM_EXTERN &&
2437  p->paramtype == REFCURSOROID)
2438  {
2439  /* Matches, so convert CURRENT OF to a param reference */
2440  cexpr->cursor_name = NULL;
2441  cexpr->cursor_param = p->paramid;
2442  }
2443  }
2444  }
2445 
2446  return (Node *) cexpr;
2447 }
2448 
2449 /*
2450  * Construct a whole-row reference to represent the notation "relation.*".
2451  */
2452 static Node *
2454  int sublevels_up, int location)
2455 {
2456  /*
2457  * Build the appropriate referencing node. Normally this can be a
2458  * whole-row Var, but if the nsitem is a JOIN USING alias then it contains
2459  * only a subset of the columns of the underlying join RTE, so that will
2460  * not work. Instead we immediately expand the reference into a RowExpr.
2461  * Since the JOIN USING's common columns are fully determined at this
2462  * point, there seems no harm in expanding it now rather than during
2463  * planning.
2464  *
2465  * Note that if the RTE is a function returning scalar, we create just a
2466  * plain reference to the function value, not a composite containing a
2467  * single column. This is pretty inconsistent at first sight, but it's
2468  * what we've done historically. One argument for it is that "rel" and
2469  * "rel.*" mean the same thing for composite relations, so why not for
2470  * scalar functions...
2471  */
2472  if (nsitem->p_names == nsitem->p_rte->eref)
2473  {
2474  Var *result;
2475 
2476  result = makeWholeRowVar(nsitem->p_rte, nsitem->p_rtindex,
2477  sublevels_up, true);
2478 
2479  /* location is not filled in by makeWholeRowVar */
2480  result->location = location;
2481 
2482  /* mark Var if it's nulled by any outer joins */
2483  markNullableIfNeeded(pstate, result);
2484 
2485  /* mark relation as requiring whole-row SELECT access */
2486  markVarForSelectPriv(pstate, result);
2487 
2488  return (Node *) result;
2489  }
2490  else
2491  {
2492  RowExpr *rowexpr;
2493  List *fields;
2494 
2495  /*
2496  * We want only as many columns as are listed in p_names->colnames,
2497  * and we should use those names not whatever possibly-aliased names
2498  * are in the RTE. We needn't worry about marking the RTE for SELECT
2499  * access, as the common columns are surely so marked already.
2500  */
2501  expandRTE(nsitem->p_rte, nsitem->p_rtindex,
2502  sublevels_up, location, false,
2503  NULL, &fields);
2504  rowexpr = makeNode(RowExpr);
2505  rowexpr->args = list_truncate(fields,
2506  list_length(nsitem->p_names->colnames));
2507  rowexpr->row_typeid = RECORDOID;
2508  rowexpr->row_format = COERCE_IMPLICIT_CAST;
2509  rowexpr->colnames = copyObject(nsitem->p_names->colnames);
2510  rowexpr->location = location;
2511 
2512  /* XXX we ought to mark the row as possibly nullable */
2513 
2514  return (Node *) rowexpr;
2515  }
2516 }
2517 
2518 /*
2519  * Handle an explicit CAST construct.
2520  *
2521  * Transform the argument, look up the type name, and apply any necessary
2522  * coercion function(s).
2523  */
2524 static Node *
2526 {
2527  Node *result;
2528  Node *arg = tc->arg;
2529  Node *expr;
2530  Oid inputType;
2531  Oid targetType;
2532  int32 targetTypmod;
2533  int location;
2534 
2535  /* Look up the type name first */
2536  typenameTypeIdAndMod(pstate, tc->typeName, &targetType, &targetTypmod);
2537 
2538  /*
2539  * If the subject of the typecast is an ARRAY[] construct and the target
2540  * type is an array type, we invoke transformArrayExpr() directly so that
2541  * we can pass down the type information. This avoids some cases where
2542  * transformArrayExpr() might not infer the correct type. Otherwise, just
2543  * transform the argument normally.
2544  */
2545  if (IsA(arg, A_ArrayExpr))
2546  {
2547  Oid targetBaseType;
2548  int32 targetBaseTypmod;
2549  Oid elementType;
2550 
2551  /*
2552  * If target is a domain over array, work with the base array type
2553  * here. Below, we'll cast the array type to the domain. In the
2554  * usual case that the target is not a domain, the remaining steps
2555  * will be a no-op.
2556  */
2557  targetBaseTypmod = targetTypmod;
2558  targetBaseType = getBaseTypeAndTypmod(targetType, &targetBaseTypmod);
2559  elementType = get_element_type(targetBaseType);
2560  if (OidIsValid(elementType))
2561  {
2562  expr = transformArrayExpr(pstate,
2563  (A_ArrayExpr *) arg,
2564  targetBaseType,
2565  elementType,
2566  targetBaseTypmod);
2567  }
2568  else
2569  expr = transformExprRecurse(pstate, arg);
2570  }
2571  else
2572  expr = transformExprRecurse(pstate, arg);
2573 
2574  inputType = exprType(expr);
2575  if (inputType == InvalidOid)
2576  return expr; /* do nothing if NULL input */
2577 
2578  /*
2579  * Location of the coercion is preferentially the location of the :: or
2580  * CAST symbol, but if there is none then use the location of the type
2581  * name (this can happen in TypeName 'string' syntax, for instance).
2582  */
2583  location = tc->location;
2584  if (location < 0)
2585  location = tc->typeName->location;
2586 
2587  result = coerce_to_target_type(pstate, expr, inputType,
2588  targetType, targetTypmod,
2591  location);
2592  if (result == NULL)
2593  ereport(ERROR,
2594  (errcode(ERRCODE_CANNOT_COERCE),
2595  errmsg("cannot cast type %s to %s",
2596  format_type_be(inputType),
2597  format_type_be(targetType)),
2598  parser_coercion_errposition(pstate, location, expr)));
2599 
2600  return result;
2601 }
2602 
2603 /*
2604  * Handle an explicit COLLATE clause.
2605  *
2606  * Transform the argument, and look up the collation name.
2607  */
2608 static Node *
2610 {
2611  CollateExpr *newc;
2612  Oid argtype;
2613 
2614  newc = makeNode(CollateExpr);
2615  newc->arg = (Expr *) transformExprRecurse(pstate, c->arg);
2616 
2617  argtype = exprType((Node *) newc->arg);
2618 
2619  /*
2620  * The unknown type is not collatable, but coerce_type() takes care of it
2621  * separately, so we'll let it go here.
2622  */
2623  if (!type_is_collatable(argtype) && argtype != UNKNOWNOID)
2624  ereport(ERROR,
2625  (errcode(ERRCODE_DATATYPE_MISMATCH),
2626  errmsg("collations are not supported by type %s",
2627  format_type_be(argtype)),
2628  parser_errposition(pstate, c->location)));
2629 
2630  newc->collOid = LookupCollation(pstate, c->collname, c->location);
2631  newc->location = c->location;
2632 
2633  return (Node *) newc;
2634 }
2635 
2636 /*
2637  * Transform a "row compare-op row" construct
2638  *
2639  * The inputs are lists of already-transformed expressions.
2640  * As with coerce_type, pstate may be NULL if no special unknown-Param
2641  * processing is wanted.
2642  *
2643  * The output may be a single OpExpr, an AND or OR combination of OpExprs,
2644  * or a RowCompareExpr. In all cases it is guaranteed to return boolean.
2645  * The AND, OR, and RowCompareExpr cases further imply things about the
2646  * behavior of the operators (ie, they behave as =, <>, or < <= > >=).
2647  */
2648 static Node *
2650  List *largs, List *rargs, int location)
2651 {
2652  RowCompareExpr *rcexpr;
2653  RowCompareType rctype;
2654  List *opexprs;
2655  List *opnos;
2656  List *opfamilies;
2657  ListCell *l,
2658  *r;
2659  List **opinfo_lists;
2660  Bitmapset *strats;
2661  int nopers;
2662  int i;
2663 
2664  nopers = list_length(largs);
2665  if (nopers != list_length(rargs))
2666  ereport(ERROR,
2667  (errcode(ERRCODE_SYNTAX_ERROR),
2668  errmsg("unequal number of entries in row expressions"),
2669  parser_errposition(pstate, location)));
2670 
2671  /*
2672  * We can't compare zero-length rows because there is no principled basis
2673  * for figuring out what the operator is.
2674  */
2675  if (nopers == 0)
2676  ereport(ERROR,
2677  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2678  errmsg("cannot compare rows of zero length"),
2679  parser_errposition(pstate, location)));
2680 
2681  /*
2682  * Identify all the pairwise operators, using make_op so that behavior is
2683  * the same as in the simple scalar case.
2684  */
2685  opexprs = NIL;
2686  forboth(l, largs, r, rargs)
2687  {
2688  Node *larg = (Node *) lfirst(l);
2689  Node *rarg = (Node *) lfirst(r);
2690  OpExpr *cmp;
2691 
2692  cmp = castNode(OpExpr, make_op(pstate, opname, larg, rarg,
2693  pstate->p_last_srf, location));
2694 
2695  /*
2696  * We don't use coerce_to_boolean here because we insist on the
2697  * operator yielding boolean directly, not via coercion. If it
2698  * doesn't yield bool it won't be in any index opfamilies...
2699  */
2700  if (cmp->opresulttype != BOOLOID)
2701  ereport(ERROR,
2702  (errcode(ERRCODE_DATATYPE_MISMATCH),
2703  errmsg("row comparison operator must yield type boolean, "
2704  "not type %s",
2705  format_type_be(cmp->opresulttype)),
2706  parser_errposition(pstate, location)));
2707  if (expression_returns_set((Node *) cmp))
2708  ereport(ERROR,
2709  (errcode(ERRCODE_DATATYPE_MISMATCH),
2710  errmsg("row comparison operator must not return a set"),
2711  parser_errposition(pstate, location)));
2712  opexprs = lappend(opexprs, cmp);
2713  }
2714 
2715  /*
2716  * If rows are length 1, just return the single operator. In this case we
2717  * don't insist on identifying btree semantics for the operator (but we
2718  * still require it to return boolean).
2719  */
2720  if (nopers == 1)
2721  return (Node *) linitial(opexprs);
2722 
2723  /*
2724  * Now we must determine which row comparison semantics (= <> < <= > >=)
2725  * apply to this set of operators. We look for btree opfamilies
2726  * containing the operators, and see which interpretations (strategy
2727  * numbers) exist for each operator.
2728  */
2729  opinfo_lists = (List **) palloc(nopers * sizeof(List *));
2730  strats = NULL;
2731  i = 0;
2732  foreach(l, opexprs)
2733  {
2734  Oid opno = ((OpExpr *) lfirst(l))->opno;
2735  Bitmapset *this_strats;
2736  ListCell *j;
2737 
2738  opinfo_lists[i] = get_op_btree_interpretation(opno);
2739 
2740  /*
2741  * convert strategy numbers into a Bitmapset to make the intersection
2742  * calculation easy.
2743  */
2744  this_strats = NULL;
2745  foreach(j, opinfo_lists[i])
2746  {
2747  OpBtreeInterpretation *opinfo = lfirst(j);
2748 
2749  this_strats = bms_add_member(this_strats, opinfo->strategy);
2750  }
2751  if (i == 0)
2752  strats = this_strats;
2753  else
2754  strats = bms_int_members(strats, this_strats);
2755  i++;
2756  }
2757 
2758  /*
2759  * If there are multiple common interpretations, we may use any one of
2760  * them ... this coding arbitrarily picks the lowest btree strategy
2761  * number.
2762  */
2763  i = bms_next_member(strats, -1);
2764  if (i < 0)
2765  {
2766  /* No common interpretation, so fail */
2767  ereport(ERROR,
2768  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2769  errmsg("could not determine interpretation of row comparison operator %s",
2770  strVal(llast(opname))),
2771  errhint("Row comparison operators must be associated with btree operator families."),
2772  parser_errposition(pstate, location)));
2773  }
2774  rctype = (RowCompareType) i;
2775 
2776  /*
2777  * For = and <> cases, we just combine the pairwise operators with AND or
2778  * OR respectively.
2779  */
2780  if (rctype == ROWCOMPARE_EQ)
2781  return (Node *) makeBoolExpr(AND_EXPR, opexprs, location);
2782  if (rctype == ROWCOMPARE_NE)
2783  return (Node *) makeBoolExpr(OR_EXPR, opexprs, location);
2784 
2785  /*
2786  * Otherwise we need to choose exactly which opfamily to associate with
2787  * each operator.
2788  */
2789  opfamilies = NIL;
2790  for (i = 0; i < nopers; i++)
2791  {
2792  Oid opfamily = InvalidOid;
2793  ListCell *j;
2794 
2795  foreach(j, opinfo_lists[i])
2796  {
2797  OpBtreeInterpretation *opinfo = lfirst(j);
2798 
2799  if (opinfo->strategy == rctype)
2800  {
2801  opfamily = opinfo->opfamily_id;
2802  break;
2803  }
2804  }
2805  if (OidIsValid(opfamily))
2806  opfamilies = lappend_oid(opfamilies, opfamily);
2807  else /* should not happen */
2808  ereport(ERROR,
2809  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2810  errmsg("could not determine interpretation of row comparison operator %s",
2811  strVal(llast(opname))),
2812  errdetail("There are multiple equally-plausible candidates."),
2813  parser_errposition(pstate, location)));
2814  }
2815 
2816  /*
2817  * Now deconstruct the OpExprs and create a RowCompareExpr.
2818  *
2819  * Note: can't just reuse the passed largs/rargs lists, because of
2820  * possibility that make_op inserted coercion operations.
2821  */
2822  opnos = NIL;
2823  largs = NIL;
2824  rargs = NIL;
2825  foreach(l, opexprs)
2826  {
2827  OpExpr *cmp = (OpExpr *) lfirst(l);
2828 
2829  opnos = lappend_oid(opnos, cmp->opno);
2830  largs = lappend(largs, linitial(cmp->args));
2831  rargs = lappend(rargs, lsecond(cmp->args));
2832  }
2833 
2834  rcexpr = makeNode(RowCompareExpr);
2835  rcexpr->rctype = rctype;
2836  rcexpr->opnos = opnos;
2837  rcexpr->opfamilies = opfamilies;
2838  rcexpr->inputcollids = NIL; /* assign_expr_collations will fix this */
2839  rcexpr->largs = largs;
2840  rcexpr->rargs = rargs;
2841 
2842  return (Node *) rcexpr;
2843 }
2844 
2845 /*
2846  * Transform a "row IS DISTINCT FROM row" construct
2847  *
2848  * The input RowExprs are already transformed
2849  */
2850 static Node *
2852  RowExpr *lrow, RowExpr *rrow,
2853  int location)
2854 {
2855  Node *result = NULL;
2856  List *largs = lrow->args;
2857  List *rargs = rrow->args;
2858  ListCell *l,
2859  *r;
2860 
2861  if (list_length(largs) != list_length(rargs))
2862  ereport(ERROR,
2863  (errcode(ERRCODE_SYNTAX_ERROR),
2864  errmsg("unequal number of entries in row expressions"),
2865  parser_errposition(pstate, location)));
2866 
2867  forboth(l, largs, r, rargs)
2868  {
2869  Node *larg = (Node *) lfirst(l);
2870  Node *rarg = (Node *) lfirst(r);
2871  Node *cmp;
2872 
2873  cmp = (Node *) make_distinct_op(pstate, opname, larg, rarg, location);
2874  if (result == NULL)
2875  result = cmp;
2876  else
2877  result = (Node *) makeBoolExpr(OR_EXPR,
2878  list_make2(result, cmp),
2879  location);
2880  }
2881 
2882  if (result == NULL)
2883  {
2884  /* zero-length rows? Generate constant FALSE */
2885  result = makeBoolConst(false, false);
2886  }
2887 
2888  return result;
2889 }
2890 
2891 /*
2892  * make the node for an IS DISTINCT FROM operator
2893  */
2894 static Expr *
2895 make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree,
2896  int location)
2897 {
2898  Expr *result;
2899 
2900  result = make_op(pstate, opname, ltree, rtree,
2901  pstate->p_last_srf, location);
2902  if (((OpExpr *) result)->opresulttype != BOOLOID)
2903  ereport(ERROR,
2904  (errcode(ERRCODE_DATATYPE_MISMATCH),
2905  errmsg("IS DISTINCT FROM requires = operator to yield boolean"),
2906  parser_errposition(pstate, location)));
2907  if (((OpExpr *) result)->opretset)
2908  ereport(ERROR,
2909  (errcode(ERRCODE_DATATYPE_MISMATCH),
2910  /* translator: %s is name of a SQL construct, eg NULLIF */
2911  errmsg("%s must not return a set", "IS DISTINCT FROM"),
2912  parser_errposition(pstate, location)));
2913 
2914  /*
2915  * We rely on DistinctExpr and OpExpr being same struct
2916  */
2917  NodeSetTag(result, T_DistinctExpr);
2918 
2919  return result;
2920 }
2921 
2922 /*
2923  * Produce a NullTest node from an IS [NOT] DISTINCT FROM NULL construct
2924  *
2925  * "arg" is the untransformed other argument
2926  */
2927 static Node *
2929 {
2930  NullTest *nt = makeNode(NullTest);
2931 
2932  nt->arg = (Expr *) transformExprRecurse(pstate, arg);
2933  /* the argument can be any type, so don't coerce it */
2934  if (distincta->kind == AEXPR_NOT_DISTINCT)
2935  nt->nulltesttype = IS_NULL;
2936  else
2937  nt->nulltesttype = IS_NOT_NULL;
2938  /* argisrow = false is correct whether or not arg is composite */
2939  nt->argisrow = false;
2940  nt->location = distincta->location;
2941  return (Node *) nt;
2942 }
2943 
2944 /*
2945  * Produce a string identifying an expression by kind.
2946  *
2947  * Note: when practical, use a simple SQL keyword for the result. If that
2948  * doesn't work well, check call sites to see whether custom error message
2949  * strings are required.
2950  */
2951 const char *
2953 {
2954  switch (exprKind)
2955  {
2956  case EXPR_KIND_NONE:
2957  return "invalid expression context";
2958  case EXPR_KIND_OTHER:
2959  return "extension expression";
2960  case EXPR_KIND_JOIN_ON:
2961  return "JOIN/ON";
2962  case EXPR_KIND_JOIN_USING:
2963  return "JOIN/USING";
2965  return "sub-SELECT in FROM";
2967  return "function in FROM";
2968  case EXPR_KIND_WHERE:
2969  return "WHERE";
2970  case EXPR_KIND_POLICY:
2971  return "POLICY";
2972  case EXPR_KIND_HAVING:
2973  return "HAVING";
2974  case EXPR_KIND_FILTER:
2975  return "FILTER";
2977  return "window PARTITION BY";
2979  return "window ORDER BY";
2981  return "window RANGE";
2983  return "window ROWS";
2985  return "window GROUPS";
2987  return "SELECT";
2989  return "INSERT";
2992  return "UPDATE";
2993  case EXPR_KIND_MERGE_WHEN:
2994  return "MERGE WHEN";
2995  case EXPR_KIND_GROUP_BY:
2996  return "GROUP BY";
2997  case EXPR_KIND_ORDER_BY:
2998  return "ORDER BY";
2999  case EXPR_KIND_DISTINCT_ON:
3000  return "DISTINCT ON";
3001  case EXPR_KIND_LIMIT:
3002  return "LIMIT";
3003  case EXPR_KIND_OFFSET:
3004  return "OFFSET";
3005  case EXPR_KIND_RETURNING:
3006  return "RETURNING";
3007  case EXPR_KIND_VALUES:
3009  return "VALUES";
3012  return "CHECK";
3015  return "DEFAULT";
3017  return "index expression";
3019  return "index predicate";
3021  return "statistics expression";
3023  return "USING";
3025  return "EXECUTE";
3027  return "WHEN";
3029  return "partition bound";
3031  return "PARTITION BY";
3033  return "CALL";
3034  case EXPR_KIND_COPY_WHERE:
3035  return "WHERE";
3037  return "GENERATED AS";
3038  case EXPR_KIND_CYCLE_MARK:
3039  return "CYCLE";
3040 
3041  /*
3042  * There is intentionally no default: case here, so that the
3043  * compiler will warn if we add a new ParseExprKind without
3044  * extending this switch. If we do see an unrecognized value at
3045  * runtime, we'll fall through to the "unrecognized" return.
3046  */
3047  }
3048  return "unrecognized expression kind";
3049 }
#define InvalidAttrNumber
Definition: attnum.h:23
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1039
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:755
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:928
signed int int32
Definition: c.h:478
#define OidIsValid(objectId)
Definition: c.h:759
char * get_database_name(Oid dbid)
Definition: dbcommands.c:3028
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1156
int errdetail(const char *fmt,...)
Definition: elog.c:1202
int errhint(const char *fmt,...)
Definition: elog.c:1316
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define _(x)
Definition: elog.c:91
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
void err(int eval, const char *fmt,...)
Definition: err.c:43
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
Oid MyDatabaseId
Definition: globals.c:89
#define MaxTupleAttributeNumber
Definition: htup_details.h:34
#define funcname
Definition: indent_codes.h:69
int b
Definition: isn.c:70
int x
Definition: isn.c:71
int a
Definition: isn.c:69
int j
Definition: isn.c:74
int i
Definition: isn.c:73
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Assert(fmt[strlen(fmt) - 1] !='\n')
List * list_truncate(List *list, int new_size)
Definition: list.c:630
List * lappend(List *list, void *datum)
Definition: list.c:338
List * lappend_oid(List *list, Oid datum)
Definition: list.c:374
List * list_concat(List *list1, const List *list2)
Definition: list.c:560
List * lcons(void *datum, List *list)
Definition: list.c:494
List * list_delete_last(List *list)
Definition: list.c:956
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2717
bool type_is_rowtype(Oid typid)
Definition: lsyscache.c:2613
List * get_op_btree_interpretation(Oid opno)
Definition: lsyscache.c:600
bool type_is_collatable(Oid typid)
Definition: lsyscache.c:3039
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2496
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2745
#define type_is_array(typid)
Definition: lsyscache.h:206
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
Definition: makefuncs.c:135
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:240
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:424
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:371
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:359
A_Expr * makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
Definition: makefuncs.c:48
char * pstrdup(const char *in)
Definition: mcxt.c:1624
void * palloc(Size size)
Definition: mcxt.c:1210
char * NameListToString(List *names)
Definition: namespace.c:3145
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:266
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:764
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1243
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:706
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
#define copyObject(obj)
Definition: nodes.h:244
#define nodeTag(nodeptr)
Definition: nodes.h:133
@ CMD_SELECT
Definition: nodes.h:276
#define NodeSetTag(nodeptr, t)
Definition: nodes.h:177
#define makeNode(_type_)
Definition: nodes.h:176
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
Node * transformGroupingFunc(ParseState *pstate, GroupingFunc *p)
Definition: parse_agg.c:248
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
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
bool verify_common_type(Oid common_type, List *exprs)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)
int parser_coercion_errposition(ParseState *pstate, int coerce_location, Node *input_expr)
Node * coerce_to_specific_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
void assign_expr_collations(ParseState *pstate, Node *expr)
static Node * make_nulltest_from_distinct(ParseState *pstate, A_Expr *distincta, Node *arg)
Definition: parse_expr.c:2928
static void unknown_attribute(ParseState *pstate, Node *relref, const char *attname, int location)
Definition: parse_expr.c:314
static Node * transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr)
Definition: parse_expr.c:2401
static Node * transformAExprOpAll(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:939
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:92
static Node * transformAExprIn(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1046
static Node * transformAExprOpAny(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:925
static Node * transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
Definition: parse_expr.c:2317
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:110
static Node * transformAExprNullIf(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1004
static bool exprIsNullConstant(Node *arg)
Definition: parse_expr.c:831
static Expr * make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, int location)
Definition: parse_expr.c:2895
static Node * transformColumnRef(ParseState *pstate, ColumnRef *cref)
Definition: parse_expr.c:432
static Node * transformCollateClause(ParseState *pstate, CollateClause *c)
Definition: parse_expr.c:2609
static Node * transformBoolExpr(ParseState *pstate, BoolExpr *a)
Definition: parse_expr.c:1298
static Node * transformFuncCall(ParseState *pstate, FuncCall *fn)
Definition: parse_expr.c:1334
static Node * transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
Definition: parse_expr.c:2149
static Node * transformCoalesceExpr(ParseState *pstate, CoalesceExpr *c)
Definition: parse_expr.c:2100
bool Transform_null_equals
Definition: parse_expr.c:42
static Node * transformSubLink(ParseState *pstate, SubLink *sublink)
Definition: parse_expr.c:1667
static Node * make_row_comparison_op(ParseState *pstate, List *opname, List *largs, List *rargs, int location)
Definition: parse_expr.c:2649
static Node * transformAExprOp(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:844
static Node * transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, Oid array_type, Oid element_type, int32 typmod)
Definition: parse_expr.c:1909
static Node * transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref)
Definition: parse_expr.c:1379
static Node * transformBooleanTest(ParseState *pstate, BooleanTest *b)
Definition: parse_expr.c:2361
static Node * make_row_distinct_op(ParseState *pstate, List *opname, RowExpr *lrow, RowExpr *rrow, int location)
Definition: parse_expr.c:2851
static Node * transformTypeCast(ParseState *pstate, TypeCast *tc)
Definition: parse_expr.c:2525
static Node * transformParamRef(ParseState *pstate, ParamRef *pref)
Definition: parse_expr.c:807
static Node * transformCaseExpr(ParseState *pstate, CaseExpr *c)
Definition: parse_expr.c:1527
static Node * transformIndirection(ParseState *pstate, A_Indirection *ind)
Definition: parse_expr.c:360
const char * ParseExprKindName(ParseExprKind exprKind)
Definition: parse_expr.c:2952
static Node * transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
Definition: parse_expr.c:2062
static Node * transformXmlExpr(ParseState *pstate, XmlExpr *x)
Definition: parse_expr.c:2188
static Node * transformAExprBetween(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1204
static Node * transformWholeRowRef(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location)
Definition: parse_expr.c:2453
static Node * transformAExprDistinct(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:953
Node * ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
Definition: parse_func.c:90
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
Definition: parse_node.c:248
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
Const * make_const(ParseState *pstate, A_Const *aconst)
Definition: parse_node.c:352
ParseExprKind
Definition: parse_node.h:39
@ EXPR_KIND_EXECUTE_PARAMETER
Definition: parse_node.h:75
@ EXPR_KIND_DOMAIN_CHECK
Definition: parse_node.h:68
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:81
@ EXPR_KIND_COLUMN_DEFAULT
Definition: parse_node.h:69
@ EXPR_KIND_DISTINCT_ON
Definition: parse_node.h:61
@ EXPR_KIND_MERGE_WHEN
Definition: parse_node.h:58
@ EXPR_KIND_STATS_EXPRESSION
Definition: parse_node.h:73
@ EXPR_KIND_INDEX_EXPRESSION
Definition: parse_node.h:71
@ EXPR_KIND_PARTITION_BOUND
Definition: parse_node.h:78
@ EXPR_KIND_FUNCTION_DEFAULT
Definition: parse_node.h:70
@ EXPR_KIND_WINDOW_FRAME_RANGE
Definition: parse_node.h:51
@ EXPR_KIND_VALUES
Definition: parse_node.h:65
@ EXPR_KIND_FROM_SUBSELECT
Definition: parse_node.h:44
@ EXPR_KIND_POLICY
Definition: parse_node.h:77
@ EXPR_KIND_WINDOW_FRAME_GROUPS
Definition: parse_node.h:53
@ EXPR_KIND_PARTITION_EXPRESSION
Definition: parse_node.h:79
@ EXPR_KIND_JOIN_USING
Definition: parse_node.h:43
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:72
@ EXPR_KIND_ORDER_BY
Definition: parse_node.h:60
@ EXPR_KIND_OFFSET
Definition: parse_node.h:63
@ EXPR_KIND_JOIN_ON
Definition: parse_node.h:42
@ EXPR_KIND_HAVING
Definition: parse_node.h:47
@ EXPR_KIND_INSERT_TARGET
Definition: parse_node.h:55
@ EXPR_KIND_ALTER_COL_TRANSFORM
Definition: parse_node.h:74
@ EXPR_KIND_LIMIT
Definition: parse_node.h:62
@ EXPR_KIND_WHERE
Definition: parse_node.h:46
@ EXPR_KIND_UPDATE_TARGET
Definition: parse_node.h:57
@ EXPR_KIND_SELECT_TARGET
Definition: parse_node.h:54
@ EXPR_KIND_RETURNING
Definition: parse_node.h:64
@ EXPR_KIND_GENERATED_COLUMN
Definition: parse_node.h:82
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_CALL_ARGUMENT
Definition: parse_node.h:80
@ EXPR_KIND_GROUP_BY
Definition: parse_node.h:59
@ EXPR_KIND_OTHER
Definition: parse_node.h:41
@ EXPR_KIND_FROM_FUNCTION
Definition: parse_node.h:45
@ EXPR_KIND_TRIGGER_WHEN
Definition: parse_node.h:76
@ EXPR_KIND_FILTER
Definition: parse_node.h:48
@ EXPR_KIND_UPDATE_SOURCE
Definition: parse_node.h:56
@ EXPR_KIND_CHECK_CONSTRAINT
Definition: parse_node.h:67
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_CYCLE_MARK
Definition: parse_node.h:83
@ EXPR_KIND_WINDOW_FRAME_ROWS
Definition: parse_node.h:52
@ EXPR_KIND_WINDOW_ORDER
Definition: parse_node.h:50
@ EXPR_KIND_VALUES_SINGLE
Definition: parse_node.h:66
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Definition: parse_oper.c:672
Expr * make_scalar_array_op(ParseState *pstate, List *opname, bool useOr, Node *ltree, Node *rtree, int location)
Definition: parse_oper.c:783
void markNullableIfNeeded(ParseState *pstate, Var *var)
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
void errorMissingColumn(ParseState *pstate, const char *relname, const char *colname, int location)
void markVarForSelectPriv(ParseState *pstate, Var *var)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
Node * scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, const char *colname, int location)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
Node * colNameToVar(ParseState *pstate, const char *colname, bool localonly, int location)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
Definition: parse_target.c:221
char * FigureColname(Node *node)
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
Definition: parse_type.c:515
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Definition: parse_type.c:310
#define ISCOMPLEX(typeid)
Definition: parse_type.h:59
@ AEXPR_BETWEEN
Definition: parsenodes.h:321
@ AEXPR_NULLIF
Definition: parsenodes.h:316
@ AEXPR_NOT_DISTINCT
Definition: parsenodes.h:315
@ AEXPR_BETWEEN_SYM
Definition: parsenodes.h:323
@ AEXPR_NOT_BETWEEN_SYM
Definition: parsenodes.h:324
@ AEXPR_ILIKE
Definition: parsenodes.h:319
@ AEXPR_IN
Definition: parsenodes.h:317
@ AEXPR_NOT_BETWEEN
Definition: parsenodes.h:322
@ AEXPR_DISTINCT
Definition: parsenodes.h:314
@ AEXPR_SIMILAR
Definition: parsenodes.h:320
@ AEXPR_LIKE
Definition: parsenodes.h:318
@ AEXPR_OP
Definition: parsenodes.h:311
@ AEXPR_OP_ANY
Definition: parsenodes.h:312
@ AEXPR_OP_ALL
Definition: parsenodes.h:313
Query * parse_sub_analyze(Node *parseTree, ParseState *parentParseState, CommonTableExpr *parentCTE, bool locked_from_parent, bool resolve_unknowns)
Definition: analyze.c:223
NameData attname
Definition: pg_attribute.h:41
void * arg
NameData relname
Definition: pg_class.h:38
#define lfirst(lc)
Definition: pg_list.h:172
#define llast(l)
Definition: pg_list.h:198
#define lfirst_node(type, lc)
Definition: pg_list.h:176
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:467
#define lthird(l)
Definition: pg_list.h:188
#define list_make1(x1)
Definition: pg_list.h:212
#define linitial(l)
Definition: pg_list.h:178
#define lsecond(l)
Definition: pg_list.h:183
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
#define lfourth(l)
Definition: pg_list.h:193
#define list_make2(x1, x2)
Definition: pg_list.h:214
#define snprintf
Definition: port.h:238
void check_stack_depth(void)
Definition: postgres.c:3461
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
char * c
e
Definition: preproc-init.c:82
@ IS_NOT_TRUE
Definition: primnodes.h:1546
@ IS_NOT_FALSE
Definition: primnodes.h:1546
@ IS_NOT_UNKNOWN
Definition: primnodes.h:1546
@ IS_TRUE
Definition: primnodes.h:1546
@ IS_UNKNOWN
Definition: primnodes.h:1546
@ IS_FALSE
Definition: primnodes.h:1546
@ ARRAY_SUBLINK
Definition: primnodes.h:930
@ MULTIEXPR_SUBLINK
Definition: primnodes.h:929
@ EXPR_SUBLINK
Definition: primnodes.h:928
@ ROWCOMPARE_SUBLINK
Definition: primnodes.h:927
@ EXISTS_SUBLINK
Definition: primnodes.h:924
@ IS_GREATEST
Definition: primnodes.h:1427
@ AND_EXPR
Definition: primnodes.h:858
@ OR_EXPR
Definition: primnodes.h:858
@ NOT_EXPR
Definition: primnodes.h:858
@ PARAM_MULTIEXPR
Definition: primnodes.h:348
@ PARAM_EXTERN
Definition: primnodes.h:345
@ PARAM_SUBLINK
Definition: primnodes.h:347
@ IS_DOCUMENT
Definition: primnodes.h:1468
@ IS_XMLFOREST
Definition: primnodes.h:1463
@ IS_XMLCONCAT
Definition: primnodes.h:1461
@ IS_XMLPI
Definition: primnodes.h:1465
@ IS_XMLPARSE
Definition: primnodes.h:1464
@ IS_XMLSERIALIZE
Definition: primnodes.h:1467
@ IS_XMLROOT
Definition: primnodes.h:1466
@ IS_XMLELEMENT
Definition: primnodes.h:1462
RowCompareType
Definition: primnodes.h:1378
@ ROWCOMPARE_NE
Definition: primnodes.h:1385
@ ROWCOMPARE_EQ
Definition: primnodes.h:1382
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:663
@ COERCE_EXPLICIT_CAST
Definition: primnodes.h:662
@ IS_NULL
Definition: primnodes.h:1522
@ IS_NOT_NULL
Definition: primnodes.h:1522
@ COERCION_EXPLICIT
Definition: primnodes.h:644
@ COERCION_IMPLICIT
Definition: primnodes.h:641
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376
bool isnull
Definition: parsenodes.h:361
int location
Definition: parsenodes.h:362
int location
Definition: parsenodes.h:336
A_Expr_Kind kind
Definition: parsenodes.h:332
char * aliasname
Definition: primnodes.h:42
List * colnames
Definition: primnodes.h:43
int location
Definition: primnodes.h:1309
List * elements
Definition: primnodes.h:1305
Expr * arg
Definition: primnodes.h:1240
int location
Definition: primnodes.h:1243
Expr * defresult
Definition: primnodes.h:1242
List * args
Definition: primnodes.h:1241
Expr * result
Definition: primnodes.h:1253
Expr * expr
Definition: primnodes.h:1252
int location
Definition: primnodes.h:1254
List * args
Definition: primnodes.h:1417
Expr * arg
Definition: primnodes.h:1206
int location
Definition: parsenodes.h:293
List * fields
Definition: parsenodes.h:292
char * cursor_name
Definition: primnodes.h:1639
Definition: pg_list.h:54
List * args
Definition: primnodes.h:1443
int location
Definition: primnodes.h:1445
MinMaxOp op
Definition: primnodes.h:1441
Expr * arg
Definition: primnodes.h:718
Definition: nodes.h:129
NullTestType nulltesttype
Definition: primnodes.h:1529
int location
Definition: primnodes.h:1532
Expr * arg
Definition: primnodes.h:1528
List * args
Definition: primnodes.h:763
int location
Definition: parsenodes.h:303
int number
Definition: parsenodes.h:302
int paramid
Definition: primnodes.h:355
Oid paramtype
Definition: primnodes.h:356
ParamKind paramkind
Definition: primnodes.h:354
int location
Definition: primnodes.h:362
RangeTblEntry * p_rte
Definition: parse_node.h:286
ParseNamespaceItem * p_target_nsitem
Definition: parse_node.h:207
ParseExprKind p_expr_kind
Definition: parse_node.h:210
List * p_multiassign_exprs
Definition: parse_node.h:212
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:236
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:234
bool p_hasSubLinks
Definition: parse_node.h:225
Node * p_last_srf
Definition: parse_node.h:228
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:235
CmdType commandType
Definition: parsenodes.h:128
List * targetList
Definition: parsenodes.h:189
Alias * eref
Definition: parsenodes.h:1200
int location
Definition: parsenodes.h:518
Node * val
Definition: parsenodes.h:517
char * name
Definition: parsenodes.h:515
RowCompareType rctype
Definition: primnodes.h:1393
int location
Definition: primnodes.h:1360
List * args
Definition: primnodes.h:1336
Definition: value.h:64
Expr * expr
Definition: primnodes.h:1731
AttrNumber resno
Definition: primnodes.h:1733
TypeName * typeName
Definition: parsenodes.h:372
int location
Definition: parsenodes.h:373
Node * arg
Definition: parsenodes.h:371
int location
Definition: parsenodes.h:273
Definition: primnodes.h:226
int location
Definition: primnodes.h:271
List * args
Definition: primnodes.h:1489
bool indent
Definition: primnodes.h:1493
int location
Definition: primnodes.h:1498
List * named_args
Definition: primnodes.h:1485
XmlExprOp op
Definition: primnodes.h:1481
TypeName * typeName
Definition: parsenodes.h:842
Node * expr
Definition: parsenodes.h:841
XmlOptionType xmloption
Definition: parsenodes.h:840
Definition: ltree.h:43
static void * fn(void *arg)
int count_nonjunk_tlist_entries(List *tlist)
Definition: tlist.c:186
String * makeString(char *str)
Definition: value.c:63
#define strVal(v)
Definition: value.h:82
bool contain_vars_of_level(Node *node, int levelsup)
Definition: var.c:441
char * map_sql_identifier_to_xml_name(const char *ident, bool fully_escaped, bool escape_period)
Definition: xml.c:2286