PostgreSQL Source Code  git master
parse_expr.c File Reference
#include "postgres.h"
#include "catalog/pg_type.h"
#include "commands/dbcommands.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/optimizer.h"
#include "parser/analyze.h"
#include "parser/parse_agg.h"
#include "parser/parse_clause.h"
#include "parser/parse_coerce.h"
#include "parser/parse_collate.h"
#include "parser/parse_expr.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_relation.h"
#include "parser/parse_target.h"
#include "parser/parse_type.h"
#include "utils/builtins.h"
#include "utils/date.h"
#include "utils/lsyscache.h"
#include "utils/timestamp.h"
#include "utils/xml.h"
Include dependency graph for parse_expr.c:

Go to the source code of this file.

Macros

#define PREC_GROUP_POSTFIX_IS   1 /* postfix IS tests (NullTest, etc) */
 
#define PREC_GROUP_INFIX_IS   2 /* infix IS (IS DISTINCT FROM, etc) */
 
#define PREC_GROUP_LESS   3 /* < > */
 
#define PREC_GROUP_EQUAL   4 /* = */
 
#define PREC_GROUP_LESS_EQUAL   5 /* <= >= <> */
 
#define PREC_GROUP_LIKE   6 /* LIKE ILIKE SIMILAR */
 
#define PREC_GROUP_BETWEEN   7 /* BETWEEN */
 
#define PREC_GROUP_IN   8 /* IN */
 
#define PREC_GROUP_NOT_LIKE   9 /* NOT LIKE/ILIKE/SIMILAR */
 
#define PREC_GROUP_NOT_BETWEEN   10 /* NOT BETWEEN */
 
#define PREC_GROUP_NOT_IN   11 /* NOT IN */
 
#define PREC_GROUP_POSTFIX_OP   12 /* generic postfix operators */
 
#define PREC_GROUP_INFIX_OP   13 /* generic infix operators */
 
#define PREC_GROUP_PREFIX_OP   14 /* generic prefix operators */
 

Functions

static NodetransformExprRecurse (ParseState *pstate, Node *expr)
 
static NodetransformParamRef (ParseState *pstate, ParamRef *pref)
 
static NodetransformAExprOp (ParseState *pstate, A_Expr *a)
 
static NodetransformAExprOpAny (ParseState *pstate, A_Expr *a)
 
static NodetransformAExprOpAll (ParseState *pstate, A_Expr *a)
 
static NodetransformAExprDistinct (ParseState *pstate, A_Expr *a)
 
static NodetransformAExprNullIf (ParseState *pstate, A_Expr *a)
 
static NodetransformAExprOf (ParseState *pstate, A_Expr *a)
 
static NodetransformAExprIn (ParseState *pstate, A_Expr *a)
 
static NodetransformAExprBetween (ParseState *pstate, A_Expr *a)
 
static NodetransformBoolExpr (ParseState *pstate, BoolExpr *a)
 
static NodetransformFuncCall (ParseState *pstate, FuncCall *fn)
 
static NodetransformMultiAssignRef (ParseState *pstate, MultiAssignRef *maref)
 
static NodetransformCaseExpr (ParseState *pstate, CaseExpr *c)
 
static NodetransformSubLink (ParseState *pstate, SubLink *sublink)
 
static NodetransformArrayExpr (ParseState *pstate, A_ArrayExpr *a, Oid array_type, Oid element_type, int32 typmod)
 
static NodetransformRowExpr (ParseState *pstate, RowExpr *r, bool allowDefault)
 
static NodetransformCoalesceExpr (ParseState *pstate, CoalesceExpr *c)
 
static NodetransformMinMaxExpr (ParseState *pstate, MinMaxExpr *m)
 
static NodetransformSQLValueFunction (ParseState *pstate, SQLValueFunction *svf)
 
static NodetransformXmlExpr (ParseState *pstate, XmlExpr *x)
 
static NodetransformXmlSerialize (ParseState *pstate, XmlSerialize *xs)
 
static NodetransformBooleanTest (ParseState *pstate, BooleanTest *b)
 
static NodetransformCurrentOfExpr (ParseState *pstate, CurrentOfExpr *cexpr)
 
static NodetransformColumnRef (ParseState *pstate, ColumnRef *cref)
 
static NodetransformWholeRowRef (ParseState *pstate, RangeTblEntry *rte, int location)
 
static NodetransformIndirection (ParseState *pstate, A_Indirection *ind)
 
static NodetransformTypeCast (ParseState *pstate, TypeCast *tc)
 
static NodetransformCollateClause (ParseState *pstate, CollateClause *c)
 
static Nodemake_row_comparison_op (ParseState *pstate, List *opname, List *largs, List *rargs, int location)
 
static Nodemake_row_distinct_op (ParseState *pstate, List *opname, RowExpr *lrow, RowExpr *rrow, int location)
 
static Exprmake_distinct_op (ParseState *pstate, List *opname, Node *ltree, Node *rtree, int location)
 
static Nodemake_nulltest_from_distinct (ParseState *pstate, A_Expr *distincta, Node *arg)
 
static int operator_precedence_group (Node *node, const char **nodename)
 
static void emit_precedence_warnings (ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
 
NodetransformExpr (ParseState *pstate, Node *expr, ParseExprKind exprKind)
 
static void unknown_attribute (ParseState *pstate, Node *relref, const char *attname, int location)
 
static bool exprIsNullConstant (Node *arg)
 
const char * ParseExprKindName (ParseExprKind exprKind)
 

Variables

bool operator_precedence_warning = false
 
bool Transform_null_equals = false
 
static const int oldprecedence_l []
 
static const int oldprecedence_r []
 

Macro Definition Documentation

◆ PREC_GROUP_BETWEEN

#define PREC_GROUP_BETWEEN   7 /* BETWEEN */

Definition at line 55 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_EQUAL

#define PREC_GROUP_EQUAL   4 /* = */

Definition at line 52 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_IN

#define PREC_GROUP_IN   8 /* IN */

◆ PREC_GROUP_INFIX_IS

#define PREC_GROUP_INFIX_IS   2 /* infix IS (IS DISTINCT FROM, etc) */

Definition at line 50 of file parse_expr.c.

Referenced by operator_precedence_group(), and transformAExprDistinct().

◆ PREC_GROUP_INFIX_OP

#define PREC_GROUP_INFIX_OP   13 /* generic infix operators */

Definition at line 61 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_LESS

#define PREC_GROUP_LESS   3 /* < > */

Definition at line 51 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_LESS_EQUAL

#define PREC_GROUP_LESS_EQUAL   5 /* <= >= <> */

Definition at line 53 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_LIKE

#define PREC_GROUP_LIKE   6 /* LIKE ILIKE SIMILAR */

Definition at line 54 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_NOT_BETWEEN

#define PREC_GROUP_NOT_BETWEEN   10 /* NOT BETWEEN */

Definition at line 58 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_NOT_IN

#define PREC_GROUP_NOT_IN   11 /* NOT IN */

◆ PREC_GROUP_NOT_LIKE

#define PREC_GROUP_NOT_LIKE   9 /* NOT LIKE/ILIKE/SIMILAR */

Definition at line 57 of file parse_expr.c.

Referenced by operator_precedence_group().

◆ PREC_GROUP_POSTFIX_IS

#define PREC_GROUP_POSTFIX_IS   1 /* postfix IS tests (NullTest, etc) */

◆ PREC_GROUP_POSTFIX_OP

#define PREC_GROUP_POSTFIX_OP   12 /* generic postfix operators */

◆ PREC_GROUP_PREFIX_OP

#define PREC_GROUP_PREFIX_OP   14 /* generic prefix operators */

Definition at line 62 of file parse_expr.c.

Referenced by emit_precedence_warnings(), and operator_precedence_group().

Function Documentation

◆ emit_precedence_warnings()

static void emit_precedence_warnings ( ParseState pstate,
int  opgroup,
const char *  opname,
Node lchild,
Node rchild,
int  location 
)
static

Definition at line 3422 of file parse_expr.c.

References Assert, ereport, errmsg(), oldprecedence_l, oldprecedence_r, operator_precedence_group(), parser_errposition(), PREC_GROUP_IN, PREC_GROUP_NOT_IN, PREC_GROUP_POSTFIX_IS, PREC_GROUP_POSTFIX_OP, PREC_GROUP_PREFIX_OP, and WARNING.

Referenced by transformAExprBetween(), transformAExprDistinct(), transformAExprIn(), transformAExprOf(), transformAExprOp(), transformAExprOpAll(), transformAExprOpAny(), transformBooleanTest(), transformExprRecurse(), transformSubLink(), and transformXmlExpr().

3426 {
3427  int cgroup;
3428  const char *copname;
3429 
3430  Assert(opgroup > 0);
3431 
3432  /*
3433  * Complain if left child, which should be same or higher precedence
3434  * according to current rules, used to be lower precedence.
3435  *
3436  * Exception to precedence rules: if left child is IN or NOT IN or a
3437  * postfix operator, the grouping is syntactically forced regardless of
3438  * precedence.
3439  */
3440  cgroup = operator_precedence_group(lchild, &copname);
3441  if (cgroup > 0)
3442  {
3443  if (oldprecedence_l[cgroup] < oldprecedence_r[opgroup] &&
3444  cgroup != PREC_GROUP_IN &&
3445  cgroup != PREC_GROUP_NOT_IN &&
3446  cgroup != PREC_GROUP_POSTFIX_OP &&
3447  cgroup != PREC_GROUP_POSTFIX_IS)
3448  ereport(WARNING,
3449  (errmsg("operator precedence change: %s is now lower precedence than %s",
3450  opname, copname),
3451  parser_errposition(pstate, location)));
3452  }
3453 
3454  /*
3455  * Complain if right child, which should be higher precedence according to
3456  * current rules, used to be same or lower precedence.
3457  *
3458  * Exception to precedence rules: if right child is a prefix operator, the
3459  * grouping is syntactically forced regardless of precedence.
3460  */
3461  cgroup = operator_precedence_group(rchild, &copname);
3462  if (cgroup > 0)
3463  {
3464  if (oldprecedence_r[cgroup] <= oldprecedence_l[opgroup] &&
3465  cgroup != PREC_GROUP_PREFIX_OP)
3466  ereport(WARNING,
3467  (errmsg("operator precedence change: %s is now lower precedence than %s",
3468  opname, copname),
3469  parser_errposition(pstate, location)));
3470  }
3471 }
#define PREC_GROUP_PREFIX_OP
Definition: parse_expr.c:62
#define PREC_GROUP_POSTFIX_IS
Definition: parse_expr.c:49
static int operator_precedence_group(Node *node, const char **nodename)
Definition: parse_expr.c:3179
#define PREC_GROUP_IN
Definition: parse_expr.c:56
#define PREC_GROUP_NOT_IN
Definition: parse_expr.c:59
#define ereport(elevel, rest)
Definition: elog.h:141
#define WARNING
Definition: elog.h:40
#define Assert(condition)
Definition: c.h:739
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
static const int oldprecedence_l[]
Definition: parse_expr.c:83
int errmsg(const char *fmt,...)
Definition: elog.c:822
static const int oldprecedence_r[]
Definition: parse_expr.c:86
#define PREC_GROUP_POSTFIX_OP
Definition: parse_expr.c:60

◆ exprIsNullConstant()

static bool exprIsNullConstant ( Node arg)
static

Definition at line 907 of file parse_expr.c.

References IsA, T_Null, Value::type, and A_Const::val.

Referenced by transformAExprDistinct(), and transformAExprOp().

908 {
909  if (arg && IsA(arg, A_Const))
910  {
911  A_Const *con = (A_Const *) arg;
912 
913  if (con->val.type == T_Null)
914  return true;
915  }
916  return false;
917 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Definition: nodes.h:292
Value val
Definition: parsenodes.h:288
NodeTag type
Definition: value.h:44

◆ make_distinct_op()

static Expr * make_distinct_op ( ParseState pstate,
List opname,
Node ltree,
Node rtree,
int  location 
)
static

Definition at line 3120 of file parse_expr.c.

References ereport, errcode(), errmsg(), ERROR, make_op(), NodeSetTag, ParseState::p_last_srf, parser_errposition(), and T_DistinctExpr.

Referenced by make_row_distinct_op(), and transformAExprDistinct().

3122 {
3123  Expr *result;
3124 
3125  result = make_op(pstate, opname, ltree, rtree,
3126  pstate->p_last_srf, location);
3127  if (((OpExpr *) result)->opresulttype != BOOLOID)
3128  ereport(ERROR,
3129  (errcode(ERRCODE_DATATYPE_MISMATCH),
3130  errmsg("IS DISTINCT FROM requires = operator to yield boolean"),
3131  parser_errposition(pstate, location)));
3132  if (((OpExpr *) result)->opretset)
3133  ereport(ERROR,
3134  (errcode(ERRCODE_DATATYPE_MISMATCH),
3135  /* translator: %s is name of a SQL construct, eg NULLIF */
3136  errmsg("%s must not return a set", "IS DISTINCT FROM"),
3137  parser_errposition(pstate, location)));
3138 
3139  /*
3140  * We rely on DistinctExpr and OpExpr being same struct
3141  */
3142  NodeSetTag(result, T_DistinctExpr);
3143 
3144  return result;
3145 }
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Definition: parse_oper.c:747
#define NodeSetTag(nodeptr, t)
Definition: nodes.h:574
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
Node * p_last_srf
Definition: parse_node.h:209
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ make_nulltest_from_distinct()

static Node * make_nulltest_from_distinct ( ParseState pstate,
A_Expr distincta,
Node arg 
)
static

Definition at line 3153 of file parse_expr.c.

References AEXPR_NOT_DISTINCT, NullTest::arg, NullTest::argisrow, IS_NOT_NULL, IS_NULL, A_Expr::kind, A_Expr::location, NullTest::location, makeNode, NullTest::nulltesttype, and transformExprRecurse().

Referenced by transformAExprDistinct().

3154 {
3155  NullTest *nt = makeNode(NullTest);
3156 
3157  nt->arg = (Expr *) transformExprRecurse(pstate, arg);
3158  /* the argument can be any type, so don't coerce it */
3159  if (distincta->kind == AEXPR_NOT_DISTINCT)
3160  nt->nulltesttype = IS_NULL;
3161  else
3162  nt->nulltesttype = IS_NOT_NULL;
3163  /* argisrow = false is correct whether or not arg is composite */
3164  nt->argisrow = false;
3165  nt->location = distincta->location;
3166  return (Node *) nt;
3167 }
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
A_Expr_Kind kind
Definition: parsenodes.h:275
Definition: nodes.h:525
Expr * arg
Definition: primnodes.h:1205
int location
Definition: parsenodes.h:279
NullTestType nulltesttype
Definition: primnodes.h:1206
#define makeNode(_type_)
Definition: nodes.h:573
int location
Definition: primnodes.h:1208
bool argisrow
Definition: primnodes.h:1207

◆ make_row_comparison_op()

static Node * make_row_comparison_op ( ParseState pstate,
List opname,
List largs,
List rargs,
int  location 
)
static

Definition at line 2874 of file parse_expr.c.

References AND_EXPR, OpExpr::args, bms_add_member(), bms_first_member(), bms_int_members(), castNode, cmp(), ereport, errcode(), errdetail(), errhint(), errmsg(), ERROR, expression_returns_set(), forboth, format_type_be(), get_op_btree_interpretation(), i, RowCompareExpr::inputcollids, InvalidOid, lappend(), lappend_oid(), RowCompareExpr::largs, lfirst, linitial, list_length(), llast, lsecond, make_op(), makeBoolExpr(), makeNode, NIL, OidIsValid, RowCompareExpr::opfamilies, OpBtreeInterpretation::opfamily_id, OpExpr::opno, RowCompareExpr::opnos, OpExpr::opresulttype, OR_EXPR, ParseState::p_last_srf, palloc(), parser_errposition(), RowCompareExpr::rargs, RowCompareExpr::rctype, ROWCOMPARE_EQ, ROWCOMPARE_NE, OpBtreeInterpretation::strategy, and strVal.

Referenced by transformAExprIn(), transformAExprOp(), and transformSubLink().

2876 {
2877  RowCompareExpr *rcexpr;
2878  RowCompareType rctype;
2879  List *opexprs;
2880  List *opnos;
2881  List *opfamilies;
2882  ListCell *l,
2883  *r;
2884  List **opinfo_lists;
2885  Bitmapset *strats;
2886  int nopers;
2887  int i;
2888 
2889  nopers = list_length(largs);
2890  if (nopers != list_length(rargs))
2891  ereport(ERROR,
2892  (errcode(ERRCODE_SYNTAX_ERROR),
2893  errmsg("unequal number of entries in row expressions"),
2894  parser_errposition(pstate, location)));
2895 
2896  /*
2897  * We can't compare zero-length rows because there is no principled basis
2898  * for figuring out what the operator is.
2899  */
2900  if (nopers == 0)
2901  ereport(ERROR,
2902  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2903  errmsg("cannot compare rows of zero length"),
2904  parser_errposition(pstate, location)));
2905 
2906  /*
2907  * Identify all the pairwise operators, using make_op so that behavior is
2908  * the same as in the simple scalar case.
2909  */
2910  opexprs = NIL;
2911  forboth(l, largs, r, rargs)
2912  {
2913  Node *larg = (Node *) lfirst(l);
2914  Node *rarg = (Node *) lfirst(r);
2915  OpExpr *cmp;
2916 
2917  cmp = castNode(OpExpr, make_op(pstate, opname, larg, rarg,
2918  pstate->p_last_srf, location));
2919 
2920  /*
2921  * We don't use coerce_to_boolean here because we insist on the
2922  * operator yielding boolean directly, not via coercion. If it
2923  * doesn't yield bool it won't be in any index opfamilies...
2924  */
2925  if (cmp->opresulttype != BOOLOID)
2926  ereport(ERROR,
2927  (errcode(ERRCODE_DATATYPE_MISMATCH),
2928  errmsg("row comparison operator must yield type boolean, "
2929  "not type %s",
2931  parser_errposition(pstate, location)));
2932  if (expression_returns_set((Node *) cmp))
2933  ereport(ERROR,
2934  (errcode(ERRCODE_DATATYPE_MISMATCH),
2935  errmsg("row comparison operator must not return a set"),
2936  parser_errposition(pstate, location)));
2937  opexprs = lappend(opexprs, cmp);
2938  }
2939 
2940  /*
2941  * If rows are length 1, just return the single operator. In this case we
2942  * don't insist on identifying btree semantics for the operator (but we
2943  * still require it to return boolean).
2944  */
2945  if (nopers == 1)
2946  return (Node *) linitial(opexprs);
2947 
2948  /*
2949  * Now we must determine which row comparison semantics (= <> < <= > >=)
2950  * apply to this set of operators. We look for btree opfamilies
2951  * containing the operators, and see which interpretations (strategy
2952  * numbers) exist for each operator.
2953  */
2954  opinfo_lists = (List **) palloc(nopers * sizeof(List *));
2955  strats = NULL;
2956  i = 0;
2957  foreach(l, opexprs)
2958  {
2959  Oid opno = ((OpExpr *) lfirst(l))->opno;
2960  Bitmapset *this_strats;
2961  ListCell *j;
2962 
2963  opinfo_lists[i] = get_op_btree_interpretation(opno);
2964 
2965  /*
2966  * convert strategy numbers into a Bitmapset to make the intersection
2967  * calculation easy.
2968  */
2969  this_strats = NULL;
2970  foreach(j, opinfo_lists[i])
2971  {
2972  OpBtreeInterpretation *opinfo = lfirst(j);
2973 
2974  this_strats = bms_add_member(this_strats, opinfo->strategy);
2975  }
2976  if (i == 0)
2977  strats = this_strats;
2978  else
2979  strats = bms_int_members(strats, this_strats);
2980  i++;
2981  }
2982 
2983  /*
2984  * If there are multiple common interpretations, we may use any one of
2985  * them ... this coding arbitrarily picks the lowest btree strategy
2986  * number.
2987  */
2988  i = bms_first_member(strats);
2989  if (i < 0)
2990  {
2991  /* No common interpretation, so fail */
2992  ereport(ERROR,
2993  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2994  errmsg("could not determine interpretation of row comparison operator %s",
2995  strVal(llast(opname))),
2996  errhint("Row comparison operators must be associated with btree operator families."),
2997  parser_errposition(pstate, location)));
2998  }
2999  rctype = (RowCompareType) i;
3000 
3001  /*
3002  * For = and <> cases, we just combine the pairwise operators with AND or
3003  * OR respectively.
3004  */
3005  if (rctype == ROWCOMPARE_EQ)
3006  return (Node *) makeBoolExpr(AND_EXPR, opexprs, location);
3007  if (rctype == ROWCOMPARE_NE)
3008  return (Node *) makeBoolExpr(OR_EXPR, opexprs, location);
3009 
3010  /*
3011  * Otherwise we need to choose exactly which opfamily to associate with
3012  * each operator.
3013  */
3014  opfamilies = NIL;
3015  for (i = 0; i < nopers; i++)
3016  {
3017  Oid opfamily = InvalidOid;
3018  ListCell *j;
3019 
3020  foreach(j, opinfo_lists[i])
3021  {
3022  OpBtreeInterpretation *opinfo = lfirst(j);
3023 
3024  if (opinfo->strategy == rctype)
3025  {
3026  opfamily = opinfo->opfamily_id;
3027  break;
3028  }
3029  }
3030  if (OidIsValid(opfamily))
3031  opfamilies = lappend_oid(opfamilies, opfamily);
3032  else /* should not happen */
3033  ereport(ERROR,
3034  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3035  errmsg("could not determine interpretation of row comparison operator %s",
3036  strVal(llast(opname))),
3037  errdetail("There are multiple equally-plausible candidates."),
3038  parser_errposition(pstate, location)));
3039  }
3040 
3041  /*
3042  * Now deconstruct the OpExprs and create a RowCompareExpr.
3043  *
3044  * Note: can't just reuse the passed largs/rargs lists, because of
3045  * possibility that make_op inserted coercion operations.
3046  */
3047  opnos = NIL;
3048  largs = NIL;
3049  rargs = NIL;
3050  foreach(l, opexprs)
3051  {
3052  OpExpr *cmp = (OpExpr *) lfirst(l);
3053 
3054  opnos = lappend_oid(opnos, cmp->opno);
3055  largs = lappend(largs, linitial(cmp->args));
3056  rargs = lappend(rargs, lsecond(cmp->args));
3057  }
3058 
3059  rcexpr = makeNode(RowCompareExpr);
3060  rcexpr->rctype = rctype;
3061  rcexpr->opnos = opnos;
3062  rcexpr->opfamilies = opfamilies;
3063  rcexpr->inputcollids = NIL; /* assign_expr_collations will fix this */
3064  rcexpr->largs = largs;
3065  rcexpr->rargs = rargs;
3066 
3067  return (Node *) rcexpr;
3068 }
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Definition: parse_oper.c:747
#define NIL
Definition: pg_list.h:65
int bms_first_member(Bitmapset *a)
Definition: bitmapset.c:996
int errhint(const char *fmt,...)
Definition: elog.c:1069
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:419
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
RowCompareType rctype
Definition: primnodes.h:1056
List * opfamilies
Definition: primnodes.h:1058
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:669
#define llast(l)
Definition: pg_list.h:215
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
#define OidIsValid(objectId)
Definition: c.h:645
#define lsecond(l)
Definition: pg_list.h:200
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:367
Oid opresulttype
Definition: primnodes.h:504
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:955
#define ereport(elevel, rest)
Definition: elog.h:141
List * lappend(List *list, void *datum)
Definition: list.c:322
List * get_op_btree_interpretation(Oid opno)
Definition: lsyscache.c:598
Node * p_last_srf
Definition: parse_node.h:209
#define InvalidOid
Definition: postgres_ext.h:36
RowCompareType
Definition: primnodes.h:1042
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
int i
Oid opno
Definition: primnodes.h:502
List * args
Definition: primnodes.h:508
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:902
List * inputcollids
Definition: primnodes.h:1059
Definition: pg_list.h:50
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ make_row_distinct_op()

static Node * make_row_distinct_op ( ParseState pstate,
List opname,
RowExpr lrow,
RowExpr rrow,
int  location 
)
static

Definition at line 3076 of file parse_expr.c.

References RowExpr::args, cmp(), ereport, errcode(), errmsg(), ERROR, forboth, lfirst, list_length(), list_make2, make_distinct_op(), makeBoolConst(), makeBoolExpr(), OR_EXPR, and parser_errposition().

Referenced by transformAExprDistinct().

3079 {
3080  Node *result = NULL;
3081  List *largs = lrow->args;
3082  List *rargs = rrow->args;
3083  ListCell *l,
3084  *r;
3085 
3086  if (list_length(largs) != list_length(rargs))
3087  ereport(ERROR,
3088  (errcode(ERRCODE_SYNTAX_ERROR),
3089  errmsg("unequal number of entries in row expressions"),
3090  parser_errposition(pstate, location)));
3091 
3092  forboth(l, largs, r, rargs)
3093  {
3094  Node *larg = (Node *) lfirst(l);
3095  Node *rarg = (Node *) lfirst(r);
3096  Node *cmp;
3097 
3098  cmp = (Node *) make_distinct_op(pstate, opname, larg, rarg, location);
3099  if (result == NULL)
3100  result = cmp;
3101  else
3102  result = (Node *) makeBoolExpr(OR_EXPR,
3103  list_make2(result, cmp),
3104  location);
3105  }
3106 
3107  if (result == NULL)
3108  {
3109  /* zero-length rows? Generate constant FALSE */
3110  result = makeBoolConst(false, false);
3111  }
3112 
3113  return result;
3114 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
List * args
Definition: primnodes.h:1008
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:419
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
static Expr * make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, int location)
Definition: parse_expr.c:3120
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:367
#define ERROR
Definition: elog.h:43
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:355
#define ereport(elevel, rest)
Definition: elog.h:141
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822
Definition: pg_list.h:50
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ operator_precedence_group()

static int operator_precedence_group ( Node node,
const char **  nodename 
)
static

Definition at line 3179 of file parse_expr.c.

References AEXPR_BETWEEN, AEXPR_BETWEEN_SYM, AEXPR_DISTINCT, AEXPR_ILIKE, AEXPR_IN, AEXPR_LIKE, AEXPR_NOT_BETWEEN, AEXPR_NOT_BETWEEN_SYM, AEXPR_NOT_DISTINCT, AEXPR_OF, AEXPR_OP, AEXPR_OP_ALL, AEXPR_OP_ANY, AEXPR_SIMILAR, ALL_SUBLINK, ANY_SUBLINK, BoolExpr::args, Assert, BoolExpr::boolop, IS_DOCUMENT, IsA, A_Expr::kind, A_Expr::lexpr, linitial, list_length(), llast, BoolExpr::location, SubLink::location, XmlExpr::location, A_Expr::name, NIL, NOT_EXPR, XmlExpr::op, SubLink::operName, PREC_GROUP_BETWEEN, PREC_GROUP_EQUAL, PREC_GROUP_IN, PREC_GROUP_INFIX_IS, PREC_GROUP_INFIX_OP, PREC_GROUP_LESS, PREC_GROUP_LESS_EQUAL, PREC_GROUP_LIKE, PREC_GROUP_NOT_BETWEEN, PREC_GROUP_NOT_IN, PREC_GROUP_NOT_LIKE, PREC_GROUP_POSTFIX_IS, PREC_GROUP_POSTFIX_OP, PREC_GROUP_PREFIX_OP, A_Expr::rexpr, strVal, and SubLink::subLinkType.

Referenced by emit_precedence_warnings(), transformAExprBetween(), and transformAExprOp().

3180 {
3181  int group = 0;
3182 
3183  *nodename = NULL;
3184  if (node == NULL)
3185  return 0;
3186 
3187  if (IsA(node, A_Expr))
3188  {
3189  A_Expr *aexpr = (A_Expr *) node;
3190 
3191  if (aexpr->kind == AEXPR_OP &&
3192  aexpr->lexpr != NULL &&
3193  aexpr->rexpr != NULL)
3194  {
3195  /* binary operator */
3196  if (list_length(aexpr->name) == 1)
3197  {
3198  *nodename = strVal(linitial(aexpr->name));
3199  /* Ignore if op was always higher priority than IS-tests */
3200  if (strcmp(*nodename, "+") == 0 ||
3201  strcmp(*nodename, "-") == 0 ||
3202  strcmp(*nodename, "*") == 0 ||
3203  strcmp(*nodename, "/") == 0 ||
3204  strcmp(*nodename, "%") == 0 ||
3205  strcmp(*nodename, "^") == 0)
3206  group = 0;
3207  else if (strcmp(*nodename, "<") == 0 ||
3208  strcmp(*nodename, ">") == 0)
3209  group = PREC_GROUP_LESS;
3210  else if (strcmp(*nodename, "=") == 0)
3211  group = PREC_GROUP_EQUAL;
3212  else if (strcmp(*nodename, "<=") == 0 ||
3213  strcmp(*nodename, ">=") == 0 ||
3214  strcmp(*nodename, "<>") == 0)
3215  group = PREC_GROUP_LESS_EQUAL;
3216  else
3217  group = PREC_GROUP_INFIX_OP;
3218  }
3219  else
3220  {
3221  /* schema-qualified operator syntax */
3222  *nodename = "OPERATOR()";
3223  group = PREC_GROUP_INFIX_OP;
3224  }
3225  }
3226  else if (aexpr->kind == AEXPR_OP &&
3227  aexpr->lexpr == NULL &&
3228  aexpr->rexpr != NULL)
3229  {
3230  /* prefix operator */
3231  if (list_length(aexpr->name) == 1)
3232  {
3233  *nodename = strVal(linitial(aexpr->name));
3234  /* Ignore if op was always higher priority than IS-tests */
3235  if (strcmp(*nodename, "+") == 0 ||
3236  strcmp(*nodename, "-") == 0)
3237  group = 0;
3238  else
3239  group = PREC_GROUP_PREFIX_OP;
3240  }
3241  else
3242  {
3243  /* schema-qualified operator syntax */
3244  *nodename = "OPERATOR()";
3245  group = PREC_GROUP_PREFIX_OP;
3246  }
3247  }
3248  else if (aexpr->kind == AEXPR_OP &&
3249  aexpr->lexpr != NULL &&
3250  aexpr->rexpr == NULL)
3251  {
3252  /* postfix operator */
3253  if (list_length(aexpr->name) == 1)
3254  {
3255  *nodename = strVal(linitial(aexpr->name));
3256  group = PREC_GROUP_POSTFIX_OP;
3257  }
3258  else
3259  {
3260  /* schema-qualified operator syntax */
3261  *nodename = "OPERATOR()";
3262  group = PREC_GROUP_POSTFIX_OP;
3263  }
3264  }
3265  else if (aexpr->kind == AEXPR_OP_ANY ||
3266  aexpr->kind == AEXPR_OP_ALL)
3267  {
3268  *nodename = strVal(llast(aexpr->name));
3269  group = PREC_GROUP_POSTFIX_OP;
3270  }
3271  else if (aexpr->kind == AEXPR_DISTINCT ||
3272  aexpr->kind == AEXPR_NOT_DISTINCT)
3273  {
3274  *nodename = "IS";
3275  group = PREC_GROUP_INFIX_IS;
3276  }
3277  else if (aexpr->kind == AEXPR_OF)
3278  {
3279  *nodename = "IS";
3280  group = PREC_GROUP_POSTFIX_IS;
3281  }
3282  else if (aexpr->kind == AEXPR_IN)
3283  {
3284  *nodename = "IN";
3285  if (strcmp(strVal(linitial(aexpr->name)), "=") == 0)
3286  group = PREC_GROUP_IN;
3287  else
3288  group = PREC_GROUP_NOT_IN;
3289  }
3290  else if (aexpr->kind == AEXPR_LIKE)
3291  {
3292  *nodename = "LIKE";
3293  if (strcmp(strVal(linitial(aexpr->name)), "~~") == 0)
3294  group = PREC_GROUP_LIKE;
3295  else
3296  group = PREC_GROUP_NOT_LIKE;
3297  }
3298  else if (aexpr->kind == AEXPR_ILIKE)
3299  {
3300  *nodename = "ILIKE";
3301  if (strcmp(strVal(linitial(aexpr->name)), "~~*") == 0)
3302  group = PREC_GROUP_LIKE;
3303  else
3304  group = PREC_GROUP_NOT_LIKE;
3305  }
3306  else if (aexpr->kind == AEXPR_SIMILAR)
3307  {
3308  *nodename = "SIMILAR";
3309  if (strcmp(strVal(linitial(aexpr->name)), "~") == 0)
3310  group = PREC_GROUP_LIKE;
3311  else
3312  group = PREC_GROUP_NOT_LIKE;
3313  }
3314  else if (aexpr->kind == AEXPR_BETWEEN ||
3315  aexpr->kind == AEXPR_BETWEEN_SYM)
3316  {
3317  Assert(list_length(aexpr->name) == 1);
3318  *nodename = strVal(linitial(aexpr->name));
3319  group = PREC_GROUP_BETWEEN;
3320  }
3321  else if (aexpr->kind == AEXPR_NOT_BETWEEN ||
3322  aexpr->kind == AEXPR_NOT_BETWEEN_SYM)
3323  {
3324  Assert(list_length(aexpr->name) == 1);
3325  *nodename = strVal(linitial(aexpr->name));
3326  group = PREC_GROUP_NOT_BETWEEN;
3327  }
3328  }
3329  else if (IsA(node, NullTest) ||
3330  IsA(node, BooleanTest))
3331  {
3332  *nodename = "IS";
3333  group = PREC_GROUP_POSTFIX_IS;
3334  }
3335  else if (IsA(node, XmlExpr))
3336  {
3337  XmlExpr *x = (XmlExpr *) node;
3338 
3339  if (x->op == IS_DOCUMENT)
3340  {
3341  *nodename = "IS";
3342  group = PREC_GROUP_POSTFIX_IS;
3343  }
3344  }
3345  else if (IsA(node, SubLink))
3346  {
3347  SubLink *s = (SubLink *) node;
3348 
3349  if (s->subLinkType == ANY_SUBLINK ||
3350  s->subLinkType == ALL_SUBLINK)
3351  {
3352  if (s->operName == NIL)
3353  {
3354  *nodename = "IN";
3355  group = PREC_GROUP_IN;
3356  }
3357  else
3358  {
3359  *nodename = strVal(llast(s->operName));
3360  group = PREC_GROUP_POSTFIX_OP;
3361  }
3362  }
3363  }
3364  else if (IsA(node, BoolExpr))
3365  {
3366  /*
3367  * Must dig into NOTs to see if it's IS NOT DOCUMENT or NOT IN. This
3368  * opens us to possibly misrecognizing, eg, NOT (x IS DOCUMENT) as a
3369  * problematic construct. We can tell the difference by checking
3370  * whether the parse locations of the two nodes are identical.
3371  *
3372  * Note that when we are comparing the child node to its own children,
3373  * we will not know that it was a NOT. Fortunately, that doesn't
3374  * matter for these cases.
3375  */
3376  BoolExpr *b = (BoolExpr *) node;
3377 
3378  if (b->boolop == NOT_EXPR)
3379  {
3380  Node *child = (Node *) linitial(b->args);
3381 
3382  if (IsA(child, XmlExpr))
3383  {
3384  XmlExpr *x = (XmlExpr *) child;
3385 
3386  if (x->op == IS_DOCUMENT &&
3387  x->location == b->location)
3388  {
3389  *nodename = "IS";
3390  group = PREC_GROUP_POSTFIX_IS;
3391  }
3392  }
3393  else if (IsA(child, SubLink))
3394  {
3395  SubLink *s = (SubLink *) child;
3396 
3397  if (s->subLinkType == ANY_SUBLINK && s->operName == NIL &&
3398  s->location == b->location)
3399  {
3400  *nodename = "IN";
3401  group = PREC_GROUP_NOT_IN;
3402  }
3403  }
3404  }
3405  }
3406  return group;
3407 }
#define NIL
Definition: pg_list.h:65
#define PREC_GROUP_PREFIX_OP
Definition: parse_expr.c:62
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#define PREC_GROUP_INFIX_OP
Definition: parse_expr.c:61
A_Expr_Kind kind
Definition: parsenodes.h:275
#define PREC_GROUP_POSTFIX_IS
Definition: parse_expr.c:49
int location
Definition: primnodes.h:1175
#define PREC_GROUP_IN
Definition: parse_expr.c:56
#define llast(l)
Definition: pg_list.h:215
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
#define PREC_GROUP_INFIX_IS
Definition: parse_expr.c:50
int location
Definition: primnodes.h:570
#define linitial(l)
Definition: pg_list.h:195
#define PREC_GROUP_BETWEEN
Definition: parse_expr.c:55
BoolExprType boolop
Definition: primnodes.h:568
#define PREC_GROUP_NOT_IN
Definition: parse_expr.c:59
Node * rexpr
Definition: parsenodes.h:278
#define PREC_GROUP_NOT_LIKE
Definition: parse_expr.c:57
Node * lexpr
Definition: parsenodes.h:277
#define PREC_GROUP_LIKE
Definition: parse_expr.c:54
XmlExprOp op
Definition: primnodes.h:1167
#define PREC_GROUP_EQUAL
Definition: parse_expr.c:52
#define Assert(condition)
Definition: c.h:739
static int list_length(const List *l)
Definition: pg_list.h:169
List * args
Definition: primnodes.h:569
List * name
Definition: parsenodes.h:276
#define PREC_GROUP_LESS
Definition: parse_expr.c:51
#define PREC_GROUP_LESS_EQUAL
Definition: parse_expr.c:53
#define PREC_GROUP_POSTFIX_OP
Definition: parse_expr.c:60
#define PREC_GROUP_NOT_BETWEEN
Definition: parse_expr.c:58

◆ ParseExprKindName()

const char* ParseExprKindName ( ParseExprKind  exprKind)

Definition at line 3481 of file parse_expr.c.

References EXPR_KIND_ALTER_COL_TRANSFORM, EXPR_KIND_CALL_ARGUMENT, EXPR_KIND_CHECK_CONSTRAINT, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_COPY_WHERE, EXPR_KIND_DISTINCT_ON, EXPR_KIND_DOMAIN_CHECK, EXPR_KIND_EXECUTE_PARAMETER, EXPR_KIND_FILTER, EXPR_KIND_FROM_FUNCTION, EXPR_KIND_FROM_SUBSELECT, EXPR_KIND_FUNCTION_DEFAULT, EXPR_KIND_GENERATED_COLUMN, EXPR_KIND_GROUP_BY, EXPR_KIND_HAVING, EXPR_KIND_INDEX_EXPRESSION, EXPR_KIND_INDEX_PREDICATE, EXPR_KIND_INSERT_TARGET, EXPR_KIND_JOIN_ON, EXPR_KIND_JOIN_USING, EXPR_KIND_LIMIT, EXPR_KIND_NONE, EXPR_KIND_OFFSET, EXPR_KIND_ORDER_BY, EXPR_KIND_OTHER, EXPR_KIND_PARTITION_BOUND, EXPR_KIND_PARTITION_EXPRESSION, EXPR_KIND_POLICY, EXPR_KIND_RETURNING, EXPR_KIND_SELECT_TARGET, EXPR_KIND_TRIGGER_WHEN, EXPR_KIND_UPDATE_SOURCE, EXPR_KIND_UPDATE_TARGET, EXPR_KIND_VALUES, EXPR_KIND_VALUES_SINGLE, EXPR_KIND_WHERE, EXPR_KIND_WINDOW_FRAME_GROUPS, EXPR_KIND_WINDOW_FRAME_RANGE, EXPR_KIND_WINDOW_FRAME_ROWS, EXPR_KIND_WINDOW_ORDER, and EXPR_KIND_WINDOW_PARTITION.

Referenced by check_agglevels_and_constraints(), check_srf_call_placement(), checkTargetlistEntrySQL92(), findTargetlistEntrySQL92(), and transformWindowFuncCall().

3482 {
3483  switch (exprKind)
3484  {
3485  case EXPR_KIND_NONE:
3486  return "invalid expression context";
3487  case EXPR_KIND_OTHER:
3488  return "extension expression";
3489  case EXPR_KIND_JOIN_ON:
3490  return "JOIN/ON";
3491  case EXPR_KIND_JOIN_USING:
3492  return "JOIN/USING";
3494  return "sub-SELECT in FROM";
3496  return "function in FROM";
3497  case EXPR_KIND_WHERE:
3498  return "WHERE";
3499  case EXPR_KIND_POLICY:
3500  return "POLICY";
3501  case EXPR_KIND_HAVING:
3502  return "HAVING";
3503  case EXPR_KIND_FILTER:
3504  return "FILTER";
3506  return "window PARTITION BY";
3508  return "window ORDER BY";
3510  return "window RANGE";
3512  return "window ROWS";
3514  return "window GROUPS";
3516  return "SELECT";
3518  return "INSERT";
3521  return "UPDATE";
3522  case EXPR_KIND_GROUP_BY:
3523  return "GROUP BY";
3524  case EXPR_KIND_ORDER_BY:
3525  return "ORDER BY";
3526  case EXPR_KIND_DISTINCT_ON:
3527  return "DISTINCT ON";
3528  case EXPR_KIND_LIMIT:
3529  return "LIMIT";
3530  case EXPR_KIND_OFFSET:
3531  return "OFFSET";
3532  case EXPR_KIND_RETURNING:
3533  return "RETURNING";
3534  case EXPR_KIND_VALUES:
3536  return "VALUES";
3539  return "CHECK";
3542  return "DEFAULT";
3544  return "index expression";
3546  return "index predicate";
3548  return "USING";
3550  return "EXECUTE";
3552  return "WHEN";
3554  return "partition bound";
3556  return "PARTITION BY";
3558  return "CALL";
3559  case EXPR_KIND_COPY_WHERE:
3560  return "WHERE";
3562  return "GENERATED AS";
3563 
3564  /*
3565  * There is intentionally no default: case here, so that the
3566  * compiler will warn if we add a new ParseExprKind without
3567  * extending this switch. If we do see an unrecognized value at
3568  * runtime, we'll fall through to the "unrecognized" return.
3569  */
3570  }
3571  return "unrecognized expression kind";
3572 }

◆ transformAExprBetween()

static Node * transformAExprBetween ( ParseState pstate,
A_Expr a 
)
static

Definition at line 1370 of file parse_expr.c.

References AEXPR_BETWEEN, AEXPR_BETWEEN_SYM, AEXPR_NOT_BETWEEN, AEXPR_NOT_BETWEEN_SYM, AEXPR_OP, AEXPR_PAREN, AND_EXPR, generate_unaccent_rules::args, Assert, castNode, copyObject, elog, emit_precedence_warnings(), ERROR, A_Expr::kind, A_Expr::lexpr, linitial, list_length(), list_make2, A_Expr::location, lsecond, makeA_Expr(), makeBoolExpr(), makeSimpleA_Expr(), NIL, operator_precedence_group(), operator_precedence_warning, OR_EXPR, A_Expr::rexpr, and transformExprRecurse().

Referenced by transformExprRecurse().

1371 {
1372  Node *aexpr;
1373  Node *bexpr;
1374  Node *cexpr;
1375  Node *result;
1376  Node *sub1;
1377  Node *sub2;
1378  List *args;
1379 
1380  /* Deconstruct A_Expr into three subexprs */
1381  aexpr = a->lexpr;
1382  args = castNode(List, a->rexpr);
1383  Assert(list_length(args) == 2);
1384  bexpr = (Node *) linitial(args);
1385  cexpr = (Node *) lsecond(args);
1386 
1388  {
1389  int opgroup;
1390  const char *opname;
1391 
1392  opgroup = operator_precedence_group((Node *) a, &opname);
1393  emit_precedence_warnings(pstate, opgroup, opname,
1394  aexpr, cexpr,
1395  a->location);
1396  /* We can ignore bexpr thanks to syntactic restrictions */
1397  /* Wrap subexpressions to prevent extra warnings */
1398  aexpr = (Node *) makeA_Expr(AEXPR_PAREN, NIL, aexpr, NULL, -1);
1399  bexpr = (Node *) makeA_Expr(AEXPR_PAREN, NIL, bexpr, NULL, -1);
1400  cexpr = (Node *) makeA_Expr(AEXPR_PAREN, NIL, cexpr, NULL, -1);
1401  }
1402 
1403  /*
1404  * Build the equivalent comparison expression. Make copies of
1405  * multiply-referenced subexpressions for safety. (XXX this is really
1406  * wrong since it results in multiple runtime evaluations of what may be
1407  * volatile expressions ...)
1408  *
1409  * Ideally we would not use hard-wired operators here but instead use
1410  * opclasses. However, mixed data types and other issues make this
1411  * difficult:
1412  * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
1413  */
1414  switch (a->kind)
1415  {
1416  case AEXPR_BETWEEN:
1417  args = list_make2(makeSimpleA_Expr(AEXPR_OP, ">=",
1418  aexpr, bexpr,
1419  a->location),
1420  makeSimpleA_Expr(AEXPR_OP, "<=",
1421  copyObject(aexpr), cexpr,
1422  a->location));
1423  result = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1424  break;
1425  case AEXPR_NOT_BETWEEN:
1426  args = list_make2(makeSimpleA_Expr(AEXPR_OP, "<",
1427  aexpr, bexpr,
1428  a->location),
1430  copyObject(aexpr), cexpr,
1431  a->location));
1432  result = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1433  break;
1434  case AEXPR_BETWEEN_SYM:
1435  args = list_make2(makeSimpleA_Expr(AEXPR_OP, ">=",
1436  aexpr, bexpr,
1437  a->location),
1438  makeSimpleA_Expr(AEXPR_OP, "<=",
1439  copyObject(aexpr), cexpr,
1440  a->location));
1441  sub1 = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1442  args = list_make2(makeSimpleA_Expr(AEXPR_OP, ">=",
1443  copyObject(aexpr), copyObject(cexpr),
1444  a->location),
1445  makeSimpleA_Expr(AEXPR_OP, "<=",
1446  copyObject(aexpr), copyObject(bexpr),
1447  a->location));
1448  sub2 = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1449  args = list_make2(sub1, sub2);
1450  result = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1451  break;
1452  case AEXPR_NOT_BETWEEN_SYM:
1453  args = list_make2(makeSimpleA_Expr(AEXPR_OP, "<",
1454  aexpr, bexpr,
1455  a->location),
1457  copyObject(aexpr), cexpr,
1458  a->location));
1459  sub1 = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1460  args = list_make2(makeSimpleA_Expr(AEXPR_OP, "<",
1461  copyObject(aexpr), copyObject(cexpr),
1462  a->location),
1464  copyObject(aexpr), copyObject(bexpr),
1465  a->location));
1466  sub2 = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1467  args = list_make2(sub1, sub2);
1468  result = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1469  break;
1470  default:
1471  elog(ERROR, "unrecognized A_Expr kind: %d", a->kind);
1472  result = NULL; /* keep compiler quiet */
1473  break;
1474  }
1475 
1476  return transformExprRecurse(pstate, result);
1477 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
A_Expr_Kind kind
Definition: parsenodes.h:275
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
static int operator_precedence_group(Node *node, const char **nodename)
Definition: parse_expr.c:3179
Definition: nodes.h:525
A_Expr * makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
Definition: makefuncs.c:48
#define lsecond(l)
Definition: pg_list.h:200
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:367
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
A_Expr * makeA_Expr(A_Expr_Kind kind, List *name, Node *lexpr, Node *rexpr, int location)
Definition: makefuncs.c:30
Node * lexpr
Definition: parsenodes.h:277
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
#define Assert(condition)
Definition: c.h:739
static int list_length(const List *l)
Definition: pg_list.h:169
#define elog(elevel,...)
Definition: elog.h:228
#define copyObject(obj)
Definition: nodes.h:641
Definition: pg_list.h:50

◆ transformAExprDistinct()

static Node * transformAExprDistinct ( ParseState pstate,
A_Expr a 
)
static

Definition at line 1067 of file parse_expr.c.

References AEXPR_NOT_DISTINCT, emit_precedence_warnings(), exprIsNullConstant(), IsA, A_Expr::kind, A_Expr::lexpr, list_make1, A_Expr::location, make_distinct_op(), make_nulltest_from_distinct(), make_row_distinct_op(), makeBoolExpr(), A_Expr::name, NOT_EXPR, operator_precedence_warning, PREC_GROUP_INFIX_IS, A_Expr::rexpr, and transformExprRecurse().

Referenced by transformExprRecurse().

1068 {
1069  Node *lexpr = a->lexpr;
1070  Node *rexpr = a->rexpr;
1071  Node *result;
1072 
1075  lexpr, rexpr,
1076  a->location);
1077 
1078  /*
1079  * If either input is an undecorated NULL literal, transform to a NullTest
1080  * on the other input. That's simpler to process than a full DistinctExpr,
1081  * and it avoids needing to require that the datatype have an = operator.
1082  */
1083  if (exprIsNullConstant(rexpr))
1084  return make_nulltest_from_distinct(pstate, a, lexpr);
1085  if (exprIsNullConstant(lexpr))
1086  return make_nulltest_from_distinct(pstate, a, rexpr);
1087 
1088  lexpr = transformExprRecurse(pstate, lexpr);
1089  rexpr = transformExprRecurse(pstate, rexpr);
1090 
1091  if (lexpr && IsA(lexpr, RowExpr) &&
1092  rexpr && IsA(rexpr, RowExpr))
1093  {
1094  /* ROW() op ROW() is handled specially */
1095  result = make_row_distinct_op(pstate, a->name,
1096  (RowExpr *) lexpr,
1097  (RowExpr *) rexpr,
1098  a->location);
1099  }
1100  else
1101  {
1102  /* Ordinary scalar operator */
1103  result = (Node *) make_distinct_op(pstate,
1104  a->name,
1105  lexpr,
1106  rexpr,
1107  a->location);
1108  }
1109 
1110  /*
1111  * If it's NOT DISTINCT, we first build a DistinctExpr and then stick a
1112  * NOT on top.
1113  */
1114  if (a->kind == AEXPR_NOT_DISTINCT)
1115  result = (Node *) makeBoolExpr(NOT_EXPR,
1116  list_make1(result),
1117  a->location);
1118 
1119  return result;
1120 }
static bool exprIsNullConstant(Node *arg)
Definition: parse_expr.c:907
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
A_Expr_Kind kind
Definition: parsenodes.h:275
Definition: nodes.h:525
static Expr * make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, int location)
Definition: parse_expr.c:3120
#define PREC_GROUP_INFIX_IS
Definition: parse_expr.c:50
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:367
#define list_make1(x1)
Definition: pg_list.h:227
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
Node * lexpr
Definition: parsenodes.h:277
bool operator_precedence_warning
Definition: parse_expr.c:42
static Node * make_row_distinct_op(ParseState *pstate, List *opname, RowExpr *lrow, RowExpr *rrow, int location)
Definition: parse_expr.c:3076
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
static Node * make_nulltest_from_distinct(ParseState *pstate, A_Expr *distincta, Node *arg)
Definition: parse_expr.c:3153
List * name
Definition: parsenodes.h:276

◆ transformAExprIn()

static Node * transformAExprIn ( ParseState pstate,
A_Expr a 
)
static

Definition at line 1210 of file parse_expr.c.

References AND_EXPR, generate_unaccent_rules::args, ArrayExpr::array_typeid, cmp(), coerce_to_boolean(), coerce_to_common_type(), contain_vars_of_level(), copyObject, ArrayExpr::element_typeid, ArrayExpr::elements, emit_precedence_warnings(), get_array_type(), InvalidOid, IsA, lappend(), A_Expr::lexpr, lfirst, linitial, list_concat(), list_length(), list_make1, list_make2, A_Expr::location, ArrayExpr::location, make_op(), make_row_comparison_op(), make_scalar_array_op(), makeBoolExpr(), makeNode, ArrayExpr::multidims, A_Expr::name, NIL, OidIsValid, operator_precedence_warning, OR_EXPR, ParseState::p_last_srf, PREC_GROUP_IN, PREC_GROUP_NOT_IN, A_Expr::rexpr, select_common_type(), strVal, and transformExprRecurse().

Referenced by transformExprRecurse().

1211 {
1212  Node *result = NULL;
1213  Node *lexpr;
1214  List *rexprs;
1215  List *rvars;
1216  List *rnonvars;
1217  bool useOr;
1218  ListCell *l;
1219 
1220  /*
1221  * If the operator is <>, combine with AND not OR.
1222  */
1223  if (strcmp(strVal(linitial(a->name)), "<>") == 0)
1224  useOr = false;
1225  else
1226  useOr = true;
1227 
1229  emit_precedence_warnings(pstate,
1230  useOr ? PREC_GROUP_IN : PREC_GROUP_NOT_IN,
1231  "IN",
1232  a->lexpr, NULL,
1233  a->location);
1234 
1235  /*
1236  * We try to generate a ScalarArrayOpExpr from IN/NOT IN, but this is only
1237  * possible if there is a suitable array type available. If not, we fall
1238  * back to a boolean condition tree with multiple copies of the lefthand
1239  * expression. Also, any IN-list items that contain Vars are handled as
1240  * separate boolean conditions, because that gives the planner more scope
1241  * for optimization on such clauses.
1242  *
1243  * First step: transform all the inputs, and detect whether any contain
1244  * Vars.
1245  */
1246  lexpr = transformExprRecurse(pstate, a->lexpr);
1247  rexprs = rvars = rnonvars = NIL;
1248  foreach(l, (List *) a->rexpr)
1249  {
1250  Node *rexpr = transformExprRecurse(pstate, lfirst(l));
1251 
1252  rexprs = lappend(rexprs, rexpr);
1253  if (contain_vars_of_level(rexpr, 0))
1254  rvars = lappend(rvars, rexpr);
1255  else
1256  rnonvars = lappend(rnonvars, rexpr);
1257  }
1258 
1259  /*
1260  * ScalarArrayOpExpr is only going to be useful if there's more than one
1261  * non-Var righthand item.
1262  */
1263  if (list_length(rnonvars) > 1)
1264  {
1265  List *allexprs;
1266  Oid scalar_type;
1267  Oid array_type;
1268 
1269  /*
1270  * Try to select a common type for the array elements. Note that
1271  * since the LHS' type is first in the list, it will be preferred when
1272  * there is doubt (eg, when all the RHS items are unknown literals).
1273  *
1274  * Note: use list_concat here not lcons, to avoid damaging rnonvars.
1275  */
1276  allexprs = list_concat(list_make1(lexpr), rnonvars);
1277  scalar_type = select_common_type(pstate, allexprs, NULL, NULL);
1278 
1279  /*
1280  * Do we have an array type to use? Aside from the case where there
1281  * isn't one, we don't risk using ScalarArrayOpExpr when the common
1282  * type is RECORD, because the RowExpr comparison logic below can cope
1283  * with some cases of non-identical row types.
1284  */
1285  if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
1286  array_type = get_array_type(scalar_type);
1287  else
1288  array_type = InvalidOid;
1289  if (array_type != InvalidOid)
1290  {
1291  /*
1292  * OK: coerce all the right-hand non-Var inputs to the common type
1293  * and build an ArrayExpr for them.
1294  */
1295  List *aexprs;
1296  ArrayExpr *newa;
1297 
1298  aexprs = NIL;
1299  foreach(l, rnonvars)
1300  {
1301  Node *rexpr = (Node *) lfirst(l);
1302 
1303  rexpr = coerce_to_common_type(pstate, rexpr,
1304  scalar_type,
1305  "IN");
1306  aexprs = lappend(aexprs, rexpr);
1307  }
1308  newa = makeNode(ArrayExpr);
1309  newa->array_typeid = array_type;
1310  /* array_collid will be set by parse_collate.c */
1311  newa->element_typeid = scalar_type;
1312  newa->elements = aexprs;
1313  newa->multidims = false;
1314  newa->location = -1;
1315 
1316  result = (Node *) make_scalar_array_op(pstate,
1317  a->name,
1318  useOr,
1319  lexpr,
1320  (Node *) newa,
1321  a->location);
1322 
1323  /* Consider only the Vars (if any) in the loop below */
1324  rexprs = rvars;
1325  }
1326  }
1327 
1328  /*
1329  * Must do it the hard way, ie, with a boolean expression tree.
1330  */
1331  foreach(l, rexprs)
1332  {
1333  Node *rexpr = (Node *) lfirst(l);
1334  Node *cmp;
1335 
1336  if (IsA(lexpr, RowExpr) &&
1337  IsA(rexpr, RowExpr))
1338  {
1339  /* ROW() op ROW() is handled specially */
1340  cmp = make_row_comparison_op(pstate,
1341  a->name,
1342  copyObject(((RowExpr *) lexpr)->args),
1343  ((RowExpr *) rexpr)->args,
1344  a->location);
1345  }
1346  else
1347  {
1348  /* Ordinary scalar operator */
1349  cmp = (Node *) make_op(pstate,
1350  a->name,
1351  copyObject(lexpr),
1352  rexpr,
1353  pstate->p_last_srf,
1354  a->location);
1355  }
1356 
1357  cmp = coerce_to_boolean(pstate, cmp, "IN");
1358  if (result == NULL)
1359  result = cmp;
1360  else
1361  result = (Node *) makeBoolExpr(useOr ? OR_EXPR : AND_EXPR,
1362  list_make2(result, cmp),
1363  a->location);
1364  }
1365 
1366  return result;
1367 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Definition: parse_oper.c:747
bool multidims
Definition: primnodes.h:978
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Expr * make_scalar_array_op(ParseState *pstate, List *opname, bool useOr, Node *ltree, Node *rtree, int location)
Definition: parse_oper.c:867
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2554
#define PREC_GROUP_IN
Definition: parse_expr.c:56
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
List * list_concat(List *list1, const List *list2)
Definition: list.c:516
Oid array_typeid
Definition: primnodes.h:974
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:645
static Node * make_row_comparison_op(ParseState *pstate, List *opname, List *largs, List *rargs, int location)
Definition: parse_expr.c:2874
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:367
#define list_make1(x1)
Definition: pg_list.h:227
#define linitial(l)
Definition: pg_list.h:195
#define PREC_GROUP_NOT_IN
Definition: parse_expr.c:59
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
List * elements
Definition: primnodes.h:977
Node * lexpr
Definition: parsenodes.h:277
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
List * lappend(List *list, void *datum)
Definition: list.c:322
int location
Definition: primnodes.h:979
Node * p_last_srf
Definition: parse_node.h:209
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
bool contain_vars_of_level(Node *node, int levelsup)
Definition: var.c:369
static int list_length(const List *l)
Definition: pg_list.h:169
List * name
Definition: parsenodes.h:276
Oid element_typeid
Definition: primnodes.h:976
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
#define copyObject(obj)
Definition: nodes.h:641
Definition: pg_list.h:50
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)

◆ transformAExprNullIf()

static Node * transformAExprNullIf ( ParseState pstate,
A_Expr a 
)
static

Definition at line 1123 of file parse_expr.c.

References OpExpr::args, ereport, errcode(), errmsg(), ERROR, exprType(), A_Expr::lexpr, linitial, A_Expr::location, make_op(), A_Expr::name, NodeSetTag, OpExpr::opresulttype, OpExpr::opretset, ParseState::p_last_srf, parser_errposition(), A_Expr::rexpr, T_NullIfExpr, and transformExprRecurse().

Referenced by transformExprRecurse().

1124 {
1125  Node *lexpr = transformExprRecurse(pstate, a->lexpr);
1126  Node *rexpr = transformExprRecurse(pstate, a->rexpr);
1127  OpExpr *result;
1128 
1129  result = (OpExpr *) make_op(pstate,
1130  a->name,
1131  lexpr,
1132  rexpr,
1133  pstate->p_last_srf,
1134  a->location);
1135 
1136  /*
1137  * The comparison operator itself should yield boolean ...
1138  */
1139  if (result->opresulttype != BOOLOID)
1140  ereport(ERROR,
1141  (errcode(ERRCODE_DATATYPE_MISMATCH),
1142  errmsg("NULLIF requires = operator to yield boolean"),
1143  parser_errposition(pstate, a->location)));
1144  if (result->opretset)
1145  ereport(ERROR,
1146  (errcode(ERRCODE_DATATYPE_MISMATCH),
1147  /* translator: %s is name of a SQL construct, eg NULLIF */
1148  errmsg("%s must not return a set", "NULLIF"),
1149  parser_errposition(pstate, a->location)));
1150 
1151  /*
1152  * ... but the NullIfExpr will yield the first operand's type.
1153  */
1154  result->opresulttype = exprType((Node *) linitial(result->args));
1155 
1156  /*
1157  * We rely on NullIfExpr and OpExpr being the same struct
1158  */
1159  NodeSetTag(result, T_NullIfExpr);
1160 
1161  return (Node *) result;
1162 }
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Definition: parse_oper.c:747
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
#define NodeSetTag(nodeptr, t)
Definition: nodes.h:574
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
Oid opresulttype
Definition: primnodes.h:504
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
#define ereport(elevel, rest)
Definition: elog.h:141
Node * lexpr
Definition: parsenodes.h:277
Node * p_last_srf
Definition: parse_node.h:209
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
List * name
Definition: parsenodes.h:276
int errmsg(const char *fmt,...)
Definition: elog.c:822
List * args
Definition: primnodes.h:508
bool opretset
Definition: primnodes.h:505

◆ transformAExprOf()

static Node * transformAExprOf ( ParseState pstate,
A_Expr a 
)
static

Definition at line 1169 of file parse_expr.c.

References emit_precedence_warnings(), exprLocation(), exprType(), A_Expr::lexpr, lfirst, linitial, Const::location, A_Expr::location, makeBoolConst(), A_Expr::name, operator_precedence_warning, PREC_GROUP_POSTFIX_IS, A_Expr::rexpr, strVal, transformExprRecurse(), and typenameTypeId().

Referenced by transformExprRecurse().

1170 {
1171  Node *lexpr = a->lexpr;
1172  Const *result;
1173  ListCell *telem;
1174  Oid ltype,
1175  rtype;
1176  bool matched = false;
1177 
1180  lexpr, NULL,
1181  a->location);
1182 
1183  lexpr = transformExprRecurse(pstate, lexpr);
1184 
1185  ltype = exprType(lexpr);
1186  foreach(telem, (List *) a->rexpr)
1187  {
1188  rtype = typenameTypeId(pstate, lfirst(telem));
1189  matched = (rtype == ltype);
1190  if (matched)
1191  break;
1192  }
1193 
1194  /*
1195  * We have two forms: equals or not equals. Flip the sense of the result
1196  * for not equals.
1197  */
1198  if (strcmp(strVal(linitial(a->name)), "<>") == 0)
1199  matched = (!matched);
1200 
1201  result = (Const *) makeBoolConst(matched, false);
1202 
1203  /* Make the result have the original input's parse location */
1204  result->location = exprLocation((Node *) a);
1205 
1206  return (Node *) result;
1207 }
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1191
#define PREC_GROUP_POSTFIX_IS
Definition: parse_expr.c:49
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial(l)
Definition: pg_list.h:195
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:355
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
Node * lexpr
Definition: parsenodes.h:277
int location
Definition: primnodes.h:207
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
#define lfirst(lc)
Definition: pg_list.h:190
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
List * name
Definition: parsenodes.h:276
Definition: pg_list.h:50
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291

◆ transformAExprOp()

static Node * transformAExprOp ( ParseState pstate,
A_Expr a 
)
static

Definition at line 920 of file parse_expr.c.

References AEXPR_PAREN, NullTest::arg, generate_unaccent_rules::args, castNode, emit_precedence_warnings(), EXPR_SUBLINK, exprIsNullConstant(), IS_NULL, IsA, A_Expr::lexpr, linitial, list_length(), A_Expr::location, SubLink::location, NullTest::location, make_op(), make_row_comparison_op(), makeNode, A_Expr::name, NullTest::nulltesttype, operator_precedence_group(), operator_precedence_warning, SubLink::operName, ParseState::p_last_srf, A_Expr::rexpr, ROWCOMPARE_SUBLINK, strVal, SubLink::subLinkType, SubLink::testexpr, Transform_null_equals, and transformExprRecurse().

Referenced by transformExprRecurse().

921 {
922  Node *lexpr = a->lexpr;
923  Node *rexpr = a->rexpr;
924  Node *result;
925 
927  {
928  int opgroup;
929  const char *opname;
930 
931  opgroup = operator_precedence_group((Node *) a, &opname);
932  if (opgroup > 0)
933  emit_precedence_warnings(pstate, opgroup, opname,
934  lexpr, rexpr,
935  a->location);
936 
937  /* Look through AEXPR_PAREN nodes so they don't affect tests below */
938  while (lexpr && IsA(lexpr, A_Expr) &&
939  ((A_Expr *) lexpr)->kind == AEXPR_PAREN)
940  lexpr = ((A_Expr *) lexpr)->lexpr;
941  while (rexpr && IsA(rexpr, A_Expr) &&
942  ((A_Expr *) rexpr)->kind == AEXPR_PAREN)
943  rexpr = ((A_Expr *) rexpr)->lexpr;
944  }
945 
946  /*
947  * Special-case "foo = NULL" and "NULL = foo" for compatibility with
948  * standards-broken products (like Microsoft's). Turn these into IS NULL
949  * exprs. (If either side is a CaseTestExpr, then the expression was
950  * generated internally from a CASE-WHEN expression, and
951  * transform_null_equals does not apply.)
952  */
953  if (Transform_null_equals &&
954  list_length(a->name) == 1 &&
955  strcmp(strVal(linitial(a->name)), "=") == 0 &&
956  (exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)) &&
957  (!IsA(lexpr, CaseTestExpr) &&!IsA(rexpr, CaseTestExpr)))
958  {
959  NullTest *n = makeNode(NullTest);
960 
961  n->nulltesttype = IS_NULL;
962  n->location = a->location;
963 
964  if (exprIsNullConstant(lexpr))
965  n->arg = (Expr *) rexpr;
966  else
967  n->arg = (Expr *) lexpr;
968 
969  result = transformExprRecurse(pstate, (Node *) n);
970  }
971  else if (lexpr && IsA(lexpr, RowExpr) &&
972  rexpr && IsA(rexpr, SubLink) &&
973  ((SubLink *) rexpr)->subLinkType == EXPR_SUBLINK)
974  {
975  /*
976  * Convert "row op subselect" into a ROWCOMPARE sublink. Formerly the
977  * grammar did this, but now that a row construct is allowed anywhere
978  * in expressions, it's easier to do it here.
979  */
980  SubLink *s = (SubLink *) rexpr;
981 
983  s->testexpr = lexpr;
984  s->operName = a->name;
985  s->location = a->location;
986  result = transformExprRecurse(pstate, (Node *) s);
987  }
988  else if (lexpr && IsA(lexpr, RowExpr) &&
989  rexpr && IsA(rexpr, RowExpr))
990  {
991  /* ROW() op ROW() is handled specially */
992  lexpr = transformExprRecurse(pstate, lexpr);
993  rexpr = transformExprRecurse(pstate, rexpr);
994 
995  result = make_row_comparison_op(pstate,
996  a->name,
997  castNode(RowExpr, lexpr)->args,
998  castNode(RowExpr, rexpr)->args,
999  a->location);
1000  }
1001  else
1002  {
1003  /* Ordinary scalar operator */
1004  Node *last_srf = pstate->p_last_srf;
1005 
1006  lexpr = transformExprRecurse(pstate, lexpr);
1007  rexpr = transformExprRecurse(pstate, rexpr);
1008 
1009  result = (Node *) make_op(pstate,
1010  a->name,
1011  lexpr,
1012  rexpr,
1013  last_srf,
1014  a->location);
1015  }
1016 
1017  return result;
1018 }
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Definition: parse_oper.c:747
static bool exprIsNullConstant(Node *arg)
Definition: parse_expr.c:907
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
static int operator_precedence_group(Node *node, const char **nodename)
Definition: parse_expr.c:3179
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
static Node * make_row_comparison_op(ParseState *pstate, List *opname, List *largs, List *rargs, int location)
Definition: parse_expr.c:2874
#define linitial(l)
Definition: pg_list.h:195
Expr * arg
Definition: primnodes.h:1205
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
Node * lexpr
Definition: parsenodes.h:277
bool Transform_null_equals
Definition: parse_expr.c:43
Node * p_last_srf
Definition: parse_node.h:209
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
NullTestType nulltesttype
Definition: primnodes.h:1206
#define makeNode(_type_)
Definition: nodes.h:573
int location
Definition: primnodes.h:1208
static int list_length(const List *l)
Definition: pg_list.h:169
List * name
Definition: parsenodes.h:276

◆ transformAExprOpAll()

static Node * transformAExprOpAll ( ParseState pstate,
A_Expr a 
)
static

Definition at line 1044 of file parse_expr.c.

References emit_precedence_warnings(), A_Expr::lexpr, llast, A_Expr::location, make_scalar_array_op(), A_Expr::name, operator_precedence_warning, PREC_GROUP_POSTFIX_OP, A_Expr::rexpr, strVal, and transformExprRecurse().

Referenced by transformExprRecurse().

1045 {
1046  Node *lexpr = a->lexpr;
1047  Node *rexpr = a->rexpr;
1048 
1051  strVal(llast(a->name)),
1052  lexpr, NULL,
1053  a->location);
1054 
1055  lexpr = transformExprRecurse(pstate, lexpr);
1056  rexpr = transformExprRecurse(pstate, rexpr);
1057 
1058  return (Node *) make_scalar_array_op(pstate,
1059  a->name,
1060  false,
1061  lexpr,
1062  rexpr,
1063  a->location);
1064 }
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
Expr * make_scalar_array_op(ParseState *pstate, List *opname, bool useOr, Node *ltree, Node *rtree, int location)
Definition: parse_oper.c:867
#define llast(l)
Definition: pg_list.h:215
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
Node * lexpr
Definition: parsenodes.h:277
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
List * name
Definition: parsenodes.h:276
#define PREC_GROUP_POSTFIX_OP
Definition: parse_expr.c:60

◆ transformAExprOpAny()

static Node * transformAExprOpAny ( ParseState pstate,
A_Expr a 
)
static

Definition at line 1021 of file parse_expr.c.

References emit_precedence_warnings(), A_Expr::lexpr, llast, A_Expr::location, make_scalar_array_op(), A_Expr::name, operator_precedence_warning, PREC_GROUP_POSTFIX_OP, A_Expr::rexpr, strVal, and transformExprRecurse().

Referenced by transformExprRecurse().

1022 {
1023  Node *lexpr = a->lexpr;
1024  Node *rexpr = a->rexpr;
1025 
1028  strVal(llast(a->name)),
1029  lexpr, NULL,
1030  a->location);
1031 
1032  lexpr = transformExprRecurse(pstate, lexpr);
1033  rexpr = transformExprRecurse(pstate, rexpr);
1034 
1035  return (Node *) make_scalar_array_op(pstate,
1036  a->name,
1037  true,
1038  lexpr,
1039  rexpr,
1040  a->location);
1041 }
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
Expr * make_scalar_array_op(ParseState *pstate, List *opname, bool useOr, Node *ltree, Node *rtree, int location)
Definition: parse_oper.c:867
#define llast(l)
Definition: pg_list.h:215
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
Node * rexpr
Definition: parsenodes.h:278
int location
Definition: parsenodes.h:279
Node * lexpr
Definition: parsenodes.h:277
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
List * name
Definition: parsenodes.h:276
#define PREC_GROUP_POSTFIX_OP
Definition: parse_expr.c:60

◆ transformArrayExpr()

static Node * transformArrayExpr ( ParseState pstate,
A_ArrayExpr a,
Oid  array_type,
Oid  element_type,
int32  typmod 
)
static

Definition at line 2098 of file parse_expr.c.

References AEXPR_PAREN, ArrayExpr::array_typeid, Assert, COERCE_EXPLICIT_CAST, coerce_to_common_type(), coerce_to_target_type(), coerce_type(), COERCION_EXPLICIT, element(), ArrayExpr::element_typeid, A_ArrayExpr::elements, ArrayExpr::elements, ereport, errcode(), errhint(), errmsg(), ERROR, exprLocation(), exprType(), format_type_be(), get_array_type(), get_element_type(), InvalidOid, IsA, lappend(), lfirst, A_ArrayExpr::location, ArrayExpr::location, makeNode, ArrayExpr::multidims, NIL, OidIsValid, parser_errposition(), select_common_type(), transformExprRecurse(), and type_is_array.

Referenced by transformExprRecurse(), and transformTypeCast().

2100 {
2101  ArrayExpr *newa = makeNode(ArrayExpr);
2102  List *newelems = NIL;
2103  List *newcoercedelems = NIL;
2104  ListCell *element;
2105  Oid coerce_type;
2106  bool coerce_hard;
2107 
2108  /*
2109  * Transform the element expressions
2110  *
2111  * Assume that the array is one-dimensional unless we find an array-type
2112  * element expression.
2113  */
2114  newa->multidims = false;
2115  foreach(element, a->elements)
2116  {
2117  Node *e = (Node *) lfirst(element);
2118  Node *newe;
2119 
2120  /* Look through AEXPR_PAREN nodes so they don't affect test below */
2121  while (e && IsA(e, A_Expr) &&
2122  ((A_Expr *) e)->kind == AEXPR_PAREN)
2123  e = ((A_Expr *) e)->lexpr;
2124 
2125  /*
2126  * If an element is itself an A_ArrayExpr, recurse directly so that we
2127  * can pass down any target type we were given.
2128  */
2129  if (IsA(e, A_ArrayExpr))
2130  {
2131  newe = transformArrayExpr(pstate,
2132  (A_ArrayExpr *) e,
2133  array_type,
2134  element_type,
2135  typmod);
2136  /* we certainly have an array here */
2137  Assert(array_type == InvalidOid || array_type == exprType(newe));
2138  newa->multidims = true;
2139  }
2140  else
2141  {
2142  newe = transformExprRecurse(pstate, e);
2143 
2144  /*
2145  * Check for sub-array expressions, if we haven't already found
2146  * one.
2147  */
2148  if (!newa->multidims && type_is_array(exprType(newe)))
2149  newa->multidims = true;
2150  }
2151 
2152  newelems = lappend(newelems, newe);
2153  }
2154 
2155  /*
2156  * Select a target type for the elements.
2157  *
2158  * If we haven't been given a target array type, we must try to deduce a
2159  * common type based on the types of the individual elements present.
2160  */
2161  if (OidIsValid(array_type))
2162  {
2163  /* Caller must ensure array_type matches element_type */
2164  Assert(OidIsValid(element_type));
2165  coerce_type = (newa->multidims ? array_type : element_type);
2166  coerce_hard = true;
2167  }
2168  else
2169  {
2170  /* Can't handle an empty array without a target type */
2171  if (newelems == NIL)
2172  ereport(ERROR,
2173  (errcode(ERRCODE_INDETERMINATE_DATATYPE),
2174  errmsg("cannot determine type of empty array"),
2175  errhint("Explicitly cast to the desired type, "
2176  "for example ARRAY[]::integer[]."),
2177  parser_errposition(pstate, a->location)));
2178 
2179  /* Select a common type for the elements */
2180  coerce_type = select_common_type(pstate, newelems, "ARRAY", NULL);
2181 
2182  if (newa->multidims)
2183  {
2184  array_type = coerce_type;
2185  element_type = get_element_type(array_type);
2186  if (!OidIsValid(element_type))
2187  ereport(ERROR,
2188  (errcode(ERRCODE_UNDEFINED_OBJECT),
2189  errmsg("could not find element type for data type %s",
2190  format_type_be(array_type)),
2191  parser_errposition(pstate, a->location)));
2192  }
2193  else
2194  {
2195  element_type = coerce_type;
2196  array_type = get_array_type(element_type);
2197  if (!OidIsValid(array_type))
2198  ereport(ERROR,
2199  (errcode(ERRCODE_UNDEFINED_OBJECT),
2200  errmsg("could not find array type for data type %s",
2201  format_type_be(element_type)),
2202  parser_errposition(pstate, a->location)));
2203  }
2204  coerce_hard = false;
2205  }
2206 
2207  /*
2208  * Coerce elements to target type
2209  *
2210  * If the array has been explicitly cast, then the elements are in turn
2211  * explicitly coerced.
2212  *
2213  * If the array's type was merely derived from the common type of its
2214  * elements, then the elements are implicitly coerced to the common type.
2215  * This is consistent with other uses of select_common_type().
2216  */
2217  foreach(element, newelems)
2218  {
2219  Node *e = (Node *) lfirst(element);
2220  Node *newe;
2221 
2222  if (coerce_hard)
2223  {
2224  newe = coerce_to_target_type(pstate, e,
2225  exprType(e),
2226  coerce_type,
2227  typmod,
2230  -1);
2231  if (newe == NULL)
2232  ereport(ERROR,
2233  (errcode(ERRCODE_CANNOT_COERCE),
2234  errmsg("cannot cast type %s to %s",
2236  format_type_be(coerce_type)),
2237  parser_errposition(pstate, exprLocation(e))));
2238  }
2239  else
2240  newe = coerce_to_common_type(pstate, e,
2241  coerce_type,
2242  "ARRAY");
2243  newcoercedelems = lappend(newcoercedelems, newe);
2244  }
2245 
2246  newa->array_typeid = array_type;
2247  /* array_collid will be set by parse_collate.c */
2248  newa->element_typeid = element_type;
2249  newa->elements = newcoercedelems;
2250  newa->location = a->location;
2251 
2252  return (Node *) newa;
2253 }
bool multidims
Definition: primnodes.h:978
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
int errhint(const char *fmt,...)
Definition: elog.c:1069
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1191
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2526
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2554
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:156
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
Oid array_typeid
Definition: primnodes.h:974
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:645
#define ERROR
Definition: elog.h:43
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
static Node * transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, Oid array_type, Oid element_type, int32 typmod)
Definition: parse_expr.c:2098
List * elements
Definition: parsenodes.h:415
List * elements
Definition: primnodes.h:977
#define ereport(elevel, rest)
Definition: elog.h:141
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
List * lappend(List *list, void *datum)
Definition: list.c:322
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:380
int location
Definition: primnodes.h:979
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
#define type_is_array(typid)
Definition: lsyscache.h:184
Oid element_typeid
Definition: primnodes.h:976
e
Definition: preproc-init.c:82
int errmsg(const char *fmt,...)
Definition: elog.c:822
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
Definition: pg_list.h:50

◆ transformBooleanTest()

static Node * transformBooleanTest ( ParseState pstate,
BooleanTest b 
)
static

Definition at line 2604 of file parse_expr.c.

References BooleanTest::arg, BooleanTest::booltesttype, coerce_to_boolean(), elog, emit_precedence_warnings(), ERROR, IS_FALSE, IS_NOT_FALSE, IS_NOT_TRUE, IS_NOT_UNKNOWN, IS_TRUE, IS_UNKNOWN, BooleanTest::location, operator_precedence_warning, PREC_GROUP_POSTFIX_IS, and transformExprRecurse().

Referenced by transformExprRecurse().

2605 {
2606  const char *clausename;
2607 
2610  (Node *) b->arg, NULL,
2611  b->location);
2612 
2613  switch (b->booltesttype)
2614  {
2615  case IS_TRUE:
2616  clausename = "IS TRUE";
2617  break;
2618  case IS_NOT_TRUE:
2619  clausename = "IS NOT TRUE";
2620  break;
2621  case IS_FALSE:
2622  clausename = "IS FALSE";
2623  break;
2624  case IS_NOT_FALSE:
2625  clausename = "IS NOT FALSE";
2626  break;
2627  case IS_UNKNOWN:
2628  clausename = "IS UNKNOWN";
2629  break;
2630  case IS_NOT_UNKNOWN:
2631  clausename = "IS NOT UNKNOWN";
2632  break;
2633  default:
2634  elog(ERROR, "unrecognized booltesttype: %d",
2635  (int) b->booltesttype);
2636  clausename = NULL; /* keep compiler quiet */
2637  }
2638 
2639  b->arg = (Expr *) transformExprRecurse(pstate, (Node *) b->arg);
2640 
2641  b->arg = (Expr *) coerce_to_boolean(pstate,
2642  (Node *) b->arg,
2643  clausename);
2644 
2645  return (Node *) b;
2646 }
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
#define PREC_GROUP_POSTFIX_IS
Definition: parse_expr.c:49
Definition: nodes.h:525
#define ERROR
Definition: elog.h:43
Expr * arg
Definition: primnodes.h:1228
BoolTestType booltesttype
Definition: primnodes.h:1229
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
#define elog(elevel,...)
Definition: elog.h:228
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)

◆ transformBoolExpr()

static Node * transformBoolExpr ( ParseState pstate,
BoolExpr a 
)
static

Definition at line 1480 of file parse_expr.c.

References AND_EXPR, generate_unaccent_rules::args, BoolExpr::args, BoolExpr::boolop, coerce_to_boolean(), elog, ERROR, lappend(), lfirst, BoolExpr::location, makeBoolExpr(), NIL, NOT_EXPR, OR_EXPR, and transformExprRecurse().

Referenced by transformExprRecurse().

1481 {
1482  List *args = NIL;
1483  const char *opname;
1484  ListCell *lc;
1485 
1486  switch (a->boolop)
1487  {
1488  case AND_EXPR:
1489  opname = "AND";
1490  break;
1491  case OR_EXPR:
1492  opname = "OR";
1493  break;
1494  case NOT_EXPR:
1495  opname = "NOT";
1496  break;
1497  default:
1498  elog(ERROR, "unrecognized boolop: %d", (int) a->boolop);
1499  opname = NULL; /* keep compiler quiet */
1500  break;
1501  }
1502 
1503  foreach(lc, a->args)
1504  {
1505  Node *arg = (Node *) lfirst(lc);
1506 
1507  arg = transformExprRecurse(pstate, arg);
1508  arg = coerce_to_boolean(pstate, arg, opname);
1509  args = lappend(args, arg);
1510  }
1511 
1512  return (Node *) makeBoolExpr(a->boolop, args, a->location);
1513 }
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
Definition: nodes.h:525
int location
Definition: primnodes.h:570
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:367
#define ERROR
Definition: elog.h:43
BoolExprType boolop
Definition: primnodes.h:568
List * lappend(List *list, void *datum)
Definition: list.c:322
#define lfirst(lc)
Definition: pg_list.h:190
List * args
Definition: primnodes.h:569
#define elog(elevel,...)
Definition: elog.h:228
void * arg
Definition: pg_list.h:50
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)

◆ transformCaseExpr()

static Node * transformCaseExpr ( ParseState pstate,
CaseExpr c 
)
static

Definition at line 1708 of file parse_expr.c.

References AEXPR_OP, arg, CaseExpr::arg, CaseExpr::args, Assert, assign_expr_collations(), CaseExpr::casetype, coerce_to_boolean(), coerce_to_common_type(), CaseTestExpr::collation, CaseExpr::defresult, ereport, errcode(), errhint(), errmsg(), ERROR, CaseWhen::expr, exprCollation(), exprLocation(), exprType(), exprTypmod(), lappend(), lcons(), lfirst, lfirst_node, A_Const::location, CaseExpr::location, CaseWhen::location, makeNode, makeSimpleA_Expr(), NIL, OidIsValid, ParseState::p_last_srf, parser_errposition(), CaseWhen::result, select_common_type(), T_Null, transformExprRecurse(), Value::type, CaseTestExpr::typeId, CaseTestExpr::typeMod, and A_Const::val.

Referenced by transformExprRecurse().

1709 {
1710  CaseExpr *newc = makeNode(CaseExpr);
1711  Node *last_srf = pstate->p_last_srf;
1712  Node *arg;
1713  CaseTestExpr *placeholder;
1714  List *newargs;
1715  List *resultexprs;
1716  ListCell *l;
1717  Node *defresult;
1718  Oid ptype;
1719 
1720  /* transform the test expression, if any */
1721  arg = transformExprRecurse(pstate, (Node *) c->arg);
1722 
1723  /* generate placeholder for test expression */
1724  if (arg)
1725  {
1726  /*
1727  * If test expression is an untyped literal, force it to text. We have
1728  * to do something now because we won't be able to do this coercion on
1729  * the placeholder. This is not as flexible as what was done in 7.4
1730  * and before, but it's good enough to handle the sort of silly coding
1731  * commonly seen.
1732  */
1733  if (exprType(arg) == UNKNOWNOID)
1734  arg = coerce_to_common_type(pstate, arg, TEXTOID, "CASE");
1735 
1736  /*
1737  * Run collation assignment on the test expression so that we know
1738  * what collation to mark the placeholder with. In principle we could
1739  * leave it to parse_collate.c to do that later, but propagating the
1740  * result to the CaseTestExpr would be unnecessarily complicated.
1741  */
1742  assign_expr_collations(pstate, arg);
1743 
1744  placeholder = makeNode(CaseTestExpr);
1745  placeholder->typeId = exprType(arg);
1746  placeholder->typeMod = exprTypmod(arg);
1747  placeholder->collation = exprCollation(arg);
1748  }
1749  else
1750  placeholder = NULL;
1751 
1752  newc->arg = (Expr *) arg;
1753 
1754  /* transform the list of arguments */
1755  newargs = NIL;
1756  resultexprs = NIL;
1757  foreach(l, c->args)
1758  {
1759  CaseWhen *w = lfirst_node(CaseWhen, l);
1760  CaseWhen *neww = makeNode(CaseWhen);
1761  Node *warg;
1762 
1763  warg = (Node *) w->expr;
1764  if (placeholder)
1765  {
1766  /* shorthand form was specified, so expand... */
1767  warg = (Node *) makeSimpleA_Expr(AEXPR_OP, "=",
1768  (Node *) placeholder,
1769  warg,
1770  w->location);
1771  }
1772  neww->expr = (Expr *) transformExprRecurse(pstate, warg);
1773 
1774  neww->expr = (Expr *) coerce_to_boolean(pstate,
1775  (Node *) neww->expr,
1776  "CASE/WHEN");
1777 
1778  warg = (Node *) w->result;
1779  neww->result = (Expr *) transformExprRecurse(pstate, warg);
1780  neww->location = w->location;
1781 
1782  newargs = lappend(newargs, neww);
1783  resultexprs = lappend(resultexprs, neww->result);
1784  }
1785 
1786  newc->args = newargs;
1787 
1788  /* transform the default clause */
1789  defresult = (Node *) c->defresult;
1790  if (defresult == NULL)
1791  {
1792  A_Const *n = makeNode(A_Const);
1793 
1794  n->val.type = T_Null;
1795  n->location = -1;
1796  defresult = (Node *) n;
1797  }
1798  newc->defresult = (Expr *) transformExprRecurse(pstate, defresult);
1799 
1800  /*
1801  * Note: default result is considered the most significant type in
1802  * determining preferred type. This is how the code worked before, but it
1803  * seems a little bogus to me --- tgl
1804  */
1805  resultexprs = lcons(newc->defresult, resultexprs);
1806 
1807  ptype = select_common_type(pstate, resultexprs, "CASE", NULL);
1808  Assert(OidIsValid(ptype));
1809  newc->casetype = ptype;
1810  /* casecollid will be set by parse_collate.c */
1811 
1812  /* Convert default result clause, if necessary */
1813  newc->defresult = (Expr *)
1814  coerce_to_common_type(pstate,
1815  (Node *) newc->defresult,
1816  ptype,
1817  "CASE/ELSE");
1818 
1819  /* Convert when-clause results, if necessary */
1820  foreach(l, newc->args)
1821  {
1822  CaseWhen *w = (CaseWhen *) lfirst(l);
1823 
1824  w->result = (Expr *)
1825  coerce_to_common_type(pstate,
1826  (Node *) w->result,
1827  ptype,
1828  "CASE/WHEN");
1829  }
1830 
1831  /* if any subexpression contained a SRF, complain */
1832  if (pstate->p_last_srf != last_srf)
1833  ereport(ERROR,
1834  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1835  /* translator: %s is name of a SQL construct, eg GROUP BY */
1836  errmsg("set-returning functions are not allowed in %s",
1837  "CASE"),
1838  errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
1839  parser_errposition(pstate,
1840  exprLocation(pstate->p_last_srf))));
1841 
1842  newc->location = c->location;
1843 
1844  return (Node *) newc;
1845 }
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
int errhint(const char *fmt,...)
Definition: elog.c:1069
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1191
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
Oid casetype
Definition: primnodes.h:916
unsigned int Oid
Definition: postgres_ext.h:31
A_Expr * makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
Definition: makefuncs.c:48
#define OidIsValid(objectId)
Definition: c.h:645
int32 typeMod
Definition: primnodes.h:959
int location
Definition: primnodes.h:932
void assign_expr_collations(ParseState *pstate, Node *expr)
#define ERROR
Definition: elog.h:43
#define lfirst_node(type, lc)
Definition: pg_list.h:193
#define ereport(elevel, rest)
Definition: elog.h:141
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
List * lappend(List *list, void *datum)
Definition: list.c:322
List * args
Definition: primnodes.h:919
Node * p_last_srf
Definition: parse_node.h:209
List * lcons(void *datum, List *list)
Definition: list.c:454
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
int location
Definition: parsenodes.h:289
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:719
int location
Definition: primnodes.h:921
Definition: nodes.h:292
int errmsg(const char *fmt,...)
Definition: elog.c:822
void * arg
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
Expr * arg
Definition: primnodes.h:918
Expr * result
Definition: primnodes.h:931
Expr * defresult
Definition: primnodes.h:920
Expr * expr
Definition: primnodes.h:930
Value val
Definition: parsenodes.h:288
Definition: pg_list.h:50
NodeTag type
Definition: value.h:44
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)

◆ transformCoalesceExpr()

static Node * transformCoalesceExpr ( ParseState pstate,
CoalesceExpr c 
)
static

Definition at line 2286 of file parse_expr.c.

References generate_unaccent_rules::args, CoalesceExpr::args, CoalesceExpr::coalescetype, coerce_to_common_type(), ereport, errcode(), errhint(), errmsg(), ERROR, exprLocation(), lappend(), lfirst, CoalesceExpr::location, makeNode, NIL, ParseState::p_last_srf, parser_errposition(), select_common_type(), and transformExprRecurse().

Referenced by transformExprRecurse().

2287 {
2289  Node *last_srf = pstate->p_last_srf;
2290  List *newargs = NIL;
2291  List *newcoercedargs = NIL;
2292  ListCell *args;
2293 
2294  foreach(args, c->args)
2295  {
2296  Node *e = (Node *) lfirst(args);
2297  Node *newe;
2298 
2299  newe = transformExprRecurse(pstate, e);
2300  newargs = lappend(newargs, newe);
2301  }
2302 
2303  newc->coalescetype = select_common_type(pstate, newargs, "COALESCE", NULL);
2304  /* coalescecollid will be set by parse_collate.c */
2305 
2306  /* Convert arguments if necessary */
2307  foreach(args, newargs)
2308  {
2309  Node *e = (Node *) lfirst(args);
2310  Node *newe;
2311 
2312  newe = coerce_to_common_type(pstate, e,
2313  newc->coalescetype,
2314  "COALESCE");
2315  newcoercedargs = lappend(newcoercedargs, newe);
2316  }
2317 
2318  /* if any subexpression contained a SRF, complain */
2319  if (pstate->p_last_srf != last_srf)
2320  ereport(ERROR,
2321  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2322  /* translator: %s is name of a SQL construct, eg GROUP BY */
2323  errmsg("set-returning functions are not allowed in %s",
2324  "COALESCE"),
2325  errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
2326  parser_errposition(pstate,
2327  exprLocation(pstate->p_last_srf))));
2328 
2329  newc->args = newcoercedargs;
2330  newc->location = c->location;
2331  return (Node *) newc;
2332 }
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
int errhint(const char *fmt,...)
Definition: elog.c:1069
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1191
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
List * args
Definition: primnodes.h:1072
#define ereport(elevel, rest)
Definition: elog.h:141
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
List * lappend(List *list, void *datum)
Definition: list.c:322
Node * p_last_srf
Definition: parse_node.h:209
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
e
Definition: preproc-init.c:82
int errmsg(const char *fmt,...)
Definition: elog.c:822
Oid coalescetype
Definition: primnodes.h:1070
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
Definition: pg_list.h:50

◆ transformCollateClause()

static Node * transformCollateClause ( ParseState pstate,
CollateClause c 
)
static

Definition at line 2834 of file parse_expr.c.

References CollateClause::arg, CollateExpr::arg, CollateClause::collname, CollateExpr::collOid, ereport, errcode(), errmsg(), ERROR, exprType(), format_type_be(), CollateClause::location, CollateExpr::location, LookupCollation(), makeNode, parser_errposition(), transformExprRecurse(), and type_is_collatable().

Referenced by transformExprRecurse().

2835 {
2836  CollateExpr *newc;
2837  Oid argtype;
2838 
2839  newc = makeNode(CollateExpr);
2840  newc->arg = (Expr *) transformExprRecurse(pstate, c->arg);
2841 
2842  argtype = exprType((Node *) newc->arg);
2843 
2844  /*
2845  * The unknown type is not collatable, but coerce_type() takes care of it
2846  * separately, so we'll let it go here.
2847  */
2848  if (!type_is_collatable(argtype) && argtype != UNKNOWNOID)
2849  ereport(ERROR,
2850  (errcode(ERRCODE_DATATYPE_MISMATCH),
2851  errmsg("collations are not supported by type %s",
2852  format_type_be(argtype)),
2853  parser_errposition(pstate, c->location)));
2854 
2855  newc->collOid = LookupCollation(pstate, c->collname, c->location);
2856  newc->location = c->location;
2857 
2858  return (Node *) newc;
2859 }
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
Definition: parse_type.c:513
#define makeNode(_type_)
Definition: nodes.h:573
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
Expr * arg
Definition: primnodes.h:886
List * collname
Definition: parsenodes.h:310
int errmsg(const char *fmt,...)
Definition: elog.c:822
int location
Definition: primnodes.h:888
bool type_is_collatable(Oid typid)
Definition: lsyscache.c:2848

◆ transformColumnRef()

static Node * transformColumnRef ( ParseState pstate,
ColumnRef cref 
)
static

Definition at line 507 of file parse_expr.c.

References _, Assert, colNameToVar(), ereport, errcode(), errmsg(), errmsg_internal(), ERROR, errorMissingColumn(), errorMissingRTE(), EXPR_KIND_ALTER_COL_TRANSFORM, EXPR_KIND_CALL_ARGUMENT, EXPR_KIND_CHECK_CONSTRAINT, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_COPY_WHERE, EXPR_KIND_DISTINCT_ON, EXPR_KIND_DOMAIN_CHECK, EXPR_KIND_EXECUTE_PARAMETER, EXPR_KIND_FILTER, EXPR_KIND_FROM_FUNCTION, EXPR_KIND_FROM_SUBSELECT, EXPR_KIND_FUNCTION_DEFAULT, EXPR_KIND_GENERATED_COLUMN, EXPR_KIND_GROUP_BY, EXPR_KIND_HAVING, EXPR_KIND_INDEX_EXPRESSION, EXPR_KIND_INDEX_PREDICATE, EXPR_KIND_INSERT_TARGET, EXPR_KIND_JOIN_ON, EXPR_KIND_JOIN_USING, EXPR_KIND_LIMIT, EXPR_KIND_NONE, EXPR_KIND_OFFSET, EXPR_KIND_ORDER_BY, EXPR_KIND_OTHER, EXPR_KIND_PARTITION_BOUND, EXPR_KIND_PARTITION_EXPRESSION, EXPR_KIND_POLICY, EXPR_KIND_RETURNING, EXPR_KIND_SELECT_TARGET, EXPR_KIND_TRIGGER_WHEN, EXPR_KIND_UPDATE_SOURCE, EXPR_KIND_UPDATE_TARGET, EXPR_KIND_VALUES, EXPR_KIND_VALUES_SINGLE, EXPR_KIND_WHERE, EXPR_KIND_WINDOW_FRAME_GROUPS, EXPR_KIND_WINDOW_FRAME_RANGE, EXPR_KIND_WINDOW_FRAME_ROWS, EXPR_KIND_WINDOW_ORDER, EXPR_KIND_WINDOW_PARTITION, ColumnRef::fields, get_database_name(), IsA, lfourth, linitial, list_length(), list_make1, ColumnRef::location, lsecond, lthird, makeRangeVar(), makeString(), MyDatabaseId, NameListToString(), ParseState::p_expr_kind, ParseState::p_last_srf, ParseState::p_post_columnref_hook, ParseState::p_pre_columnref_hook, ParseFuncOrColumn(), parser_errposition(), refnameRangeTblEntry(), relname, scanRTEForColumn(), strVal, and transformWholeRowRef().

Referenced by transformExprRecurse().

508 {
509  Node *node = NULL;
510  char *nspname = NULL;
511  char *relname = NULL;
512  char *colname = NULL;
513  RangeTblEntry *rte;
514  int levels_up;
515  enum
516  {
517  CRERR_NO_COLUMN,
518  CRERR_NO_RTE,
519  CRERR_WRONG_DB,
520  CRERR_TOO_MANY
521  } crerr = CRERR_NO_COLUMN;
522  const char *err;
523 
524  /*
525  * Check to see if the column reference is in an invalid place within the
526  * query. We allow column references in most places, except in default
527  * expressions and partition bound expressions.
528  */
529  err = NULL;
530  switch (pstate->p_expr_kind)
531  {
532  case EXPR_KIND_NONE:
533  Assert(false); /* can't happen */
534  break;
535  case EXPR_KIND_OTHER:
536  case EXPR_KIND_JOIN_ON:
540  case EXPR_KIND_WHERE:
541  case EXPR_KIND_POLICY:
542  case EXPR_KIND_HAVING:
543  case EXPR_KIND_FILTER:
553  case EXPR_KIND_GROUP_BY:
554  case EXPR_KIND_ORDER_BY:
556  case EXPR_KIND_LIMIT:
557  case EXPR_KIND_OFFSET:
558  case EXPR_KIND_RETURNING:
559  case EXPR_KIND_VALUES:
573  /* okay */
574  break;
575 
577  err = _("cannot use column reference in DEFAULT expression");
578  break;
580  err = _("cannot use column reference in partition bound expression");
581  break;
582 
583  /*
584  * There is intentionally no default: case here, so that the
585  * compiler will warn if we add a new ParseExprKind without
586  * extending this switch. If we do see an unrecognized value at
587  * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
588  * which is sane anyway.
589  */
590  }
591  if (err)
592  ereport(ERROR,
593  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
594  errmsg_internal("%s", err),
595  parser_errposition(pstate, cref->location)));
596 
597  /*
598  * Give the PreParseColumnRefHook, if any, first shot. If it returns
599  * non-null then that's all, folks.
600  */
601  if (pstate->p_pre_columnref_hook != NULL)
602  {
603  node = pstate->p_pre_columnref_hook(pstate, cref);
604  if (node != NULL)
605  return node;
606  }
607 
608  /*----------
609  * The allowed syntaxes are:
610  *
611  * A First try to resolve as unqualified column name;
612  * if no luck, try to resolve as unqualified table name (A.*).
613  * A.B A is an unqualified table name; B is either a
614  * column or function name (trying column name first).
615  * A.B.C schema A, table B, col or func name C.
616  * A.B.C.D catalog A, schema B, table C, col or func D.
617  * A.* A is an unqualified table name; means whole-row value.
618  * A.B.* whole-row value of table B in schema A.
619  * A.B.C.* whole-row value of table C in schema B in catalog A.
620  *
621  * We do not need to cope with bare "*"; that will only be accepted by
622  * the grammar at the top level of a SELECT list, and transformTargetList
623  * will take care of it before it ever gets here. Also, "A.*" etc will
624  * be expanded by transformTargetList if they appear at SELECT top level,
625  * so here we are only going to see them as function or operator inputs.
626  *
627  * Currently, if a catalog name is given then it must equal the current
628  * database name; we check it here and then discard it.
629  *----------
630  */
631  switch (list_length(cref->fields))
632  {
633  case 1:
634  {
635  Node *field1 = (Node *) linitial(cref->fields);
636 
637  Assert(IsA(field1, String));
638  colname = strVal(field1);
639 
640  /* Try to identify as an unqualified column */
641  node = colNameToVar(pstate, colname, false, cref->location);
642 
643  if (node == NULL)
644  {
645  /*
646  * Not known as a column of any range-table entry.
647  *
648  * Try to find the name as a relation. Note that only
649  * relations already entered into the rangetable will be
650  * recognized.
651  *
652  * This is a hack for backwards compatibility with
653  * PostQUEL-inspired syntax. The preferred form now is
654  * "rel.*".
655  */
656  rte = refnameRangeTblEntry(pstate, NULL, colname,
657  cref->location,
658  &levels_up);
659  if (rte)
660  node = transformWholeRowRef(pstate, rte,
661  cref->location);
662  }
663  break;
664  }
665  case 2:
666  {
667  Node *field1 = (Node *) linitial(cref->fields);
668  Node *field2 = (Node *) lsecond(cref->fields);
669 
670  Assert(IsA(field1, String));
671  relname = strVal(field1);
672 
673  /* Locate the referenced RTE */
674  rte = refnameRangeTblEntry(pstate, nspname, relname,
675  cref->location,
676  &levels_up);
677  if (rte == NULL)
678  {
679  crerr = CRERR_NO_RTE;
680  break;
681  }
682 
683  /* Whole-row reference? */
684  if (IsA(field2, A_Star))
685  {
686  node = transformWholeRowRef(pstate, rte, cref->location);
687  break;
688  }
689 
690  Assert(IsA(field2, String));
691  colname = strVal(field2);
692 
693  /* Try to identify as a column of the RTE */
694  node = scanRTEForColumn(pstate, rte, colname, cref->location,
695  0, NULL);
696  if (node == NULL)
697  {
698  /* Try it as a function call on the whole row */
699  node = transformWholeRowRef(pstate, rte, cref->location);
700  node = ParseFuncOrColumn(pstate,
701  list_make1(makeString(colname)),
702  list_make1(node),
703  pstate->p_last_srf,
704  NULL,
705  false,
706  cref->location);
707  }
708  break;
709  }
710  case 3:
711  {
712  Node *field1 = (Node *) linitial(cref->fields);
713  Node *field2 = (Node *) lsecond(cref->fields);
714  Node *field3 = (Node *) lthird(cref->fields);
715 
716  Assert(IsA(field1, String));
717  nspname = strVal(field1);
718  Assert(IsA(field2, String));
719  relname = strVal(field2);
720 
721  /* Locate the referenced RTE */
722  rte = refnameRangeTblEntry(pstate, nspname, relname,
723  cref->location,
724  &levels_up);
725  if (rte == NULL)
726  {
727  crerr = CRERR_NO_RTE;
728  break;
729  }
730 
731  /* Whole-row reference? */
732  if (IsA(field3, A_Star))
733  {
734  node = transformWholeRowRef(pstate, rte, cref->location);
735  break;
736  }
737 
738  Assert(IsA(field3, String));
739  colname = strVal(field3);
740 
741  /* Try to identify as a column of the RTE */
742  node = scanRTEForColumn(pstate, rte, colname, cref->location,
743  0, NULL);
744  if (node == NULL)
745  {
746  /* Try it as a function call on the whole row */
747  node = transformWholeRowRef(pstate, rte, cref->location);
748  node = ParseFuncOrColumn(pstate,
749  list_make1(makeString(colname)),
750  list_make1(node),
751  pstate->p_last_srf,
752  NULL,
753  false,
754  cref->location);
755  }
756  break;
757  }
758  case 4:
759  {
760  Node *field1 = (Node *) linitial(cref->fields);
761  Node *field2 = (Node *) lsecond(cref->fields);
762  Node *field3 = (Node *) lthird(cref->fields);
763  Node *field4 = (Node *) lfourth(cref->fields);
764  char *catname;
765 
766  Assert(IsA(field1, String));
767  catname = strVal(field1);
768  Assert(IsA(field2, String));
769  nspname = strVal(field2);
770  Assert(IsA(field3, String));
771  relname = strVal(field3);
772 
773  /*
774  * We check the catalog name and then ignore it.
775  */
776  if (strcmp(catname, get_database_name(MyDatabaseId)) != 0)
777  {
778  crerr = CRERR_WRONG_DB;
779  break;
780  }
781 
782  /* Locate the referenced RTE */
783  rte = refnameRangeTblEntry(pstate, nspname, relname,
784  cref->location,
785  &levels_up);
786  if (rte == NULL)
787  {
788  crerr = CRERR_NO_RTE;
789  break;
790  }
791 
792  /* Whole-row reference? */
793  if (IsA(field4, A_Star))
794  {
795  node = transformWholeRowRef(pstate, rte, cref->location);
796  break;
797  }
798 
799  Assert(IsA(field4, String));
800  colname = strVal(field4);
801 
802  /* Try to identify as a column of the RTE */
803  node = scanRTEForColumn(pstate, rte, colname, cref->location,
804  0, NULL);
805  if (node == NULL)
806  {
807  /* Try it as a function call on the whole row */
808  node = transformWholeRowRef(pstate, rte, cref->location);
809  node = ParseFuncOrColumn(pstate,
810  list_make1(makeString(colname)),
811  list_make1(node),
812  pstate->p_last_srf,
813  NULL,
814  false,
815  cref->location);
816  }
817  break;
818  }
819  default:
820  crerr = CRERR_TOO_MANY; /* too many dotted names */
821  break;
822  }
823 
824  /*
825  * Now give the PostParseColumnRefHook, if any, a chance. We pass the
826  * translation-so-far so that it can throw an error if it wishes in the
827  * case that it has a conflicting interpretation of the ColumnRef. (If it
828  * just translates anyway, we'll throw an error, because we can't undo
829  * whatever effects the preceding steps may have had on the pstate.) If it
830  * returns NULL, use the standard translation, or throw a suitable error
831  * if there is none.
832  */
833  if (pstate->p_post_columnref_hook != NULL)
834  {
835  Node *hookresult;
836 
837  hookresult = pstate->p_post_columnref_hook(pstate, cref, node);
838  if (node == NULL)
839  node = hookresult;
840  else if (hookresult != NULL)
841  ereport(ERROR,
842  (errcode(ERRCODE_AMBIGUOUS_COLUMN),
843  errmsg("column reference \"%s\" is ambiguous",
844  NameListToString(cref->fields)),
845  parser_errposition(pstate, cref->location)));
846  }
847 
848  /*
849  * Throw error if no translation found.
850  */
851  if (node == NULL)
852  {
853  switch (crerr)
854  {
855  case CRERR_NO_COLUMN:
856  errorMissingColumn(pstate, relname, colname, cref->location);
857  break;
858  case CRERR_NO_RTE:
859  errorMissingRTE(pstate, makeRangeVar(nspname, relname,
860  cref->location));
861  break;
862  case CRERR_WRONG_DB:
863  ereport(ERROR,
864  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
865  errmsg("cross-database references are not implemented: %s",
866  NameListToString(cref->fields)),
867  parser_errposition(pstate, cref->location)));
868  break;
869  case CRERR_TOO_MANY:
870  ereport(ERROR,
871  (errcode(ERRCODE_SYNTAX_ERROR),
872  errmsg("improper qualified name (too many dotted names): %s",
873  NameListToString(cref->fields)),
874  parser_errposition(pstate, cref->location)));
875  break;
876  }
877  }
878 
879  return node;
880 }
Value * makeString(char *str)
Definition: value.c:53
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
void errorMissingColumn(ParseState *pstate, const char *relname, const char *colname, int location)
NameData relname
Definition: pg_class.h:35
RangeTblEntry * refnameRangeTblEntry(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
#define lsecond(l)
Definition: pg_list.h:200
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:216
int location
Definition: parsenodes.h:236
#define list_make1(x1)
Definition: pg_list.h:227
#define linitial(l)
Definition: pg_list.h:195
Node * scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, const char *colname, int location, int fuzzy_rte_penalty, FuzzyAttrMatchState *fuzzystate)
#define ERROR
Definition: elog.h:43
Node * ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
Definition: parse_func.c:88
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2155
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
#define ereport(elevel, rest)
Definition: elog.h:141
char * NameListToString(List *names)
Definition: namespace.c:3094
Node * p_last_srf
Definition: parse_node.h:209
Oid MyDatabaseId
Definition: globals.c:85
static Node * transformWholeRowRef(ParseState *pstate, RangeTblEntry *rte, int location)
Definition: parse_expr.c:2706
ParseExprKind p_expr_kind
Definition: parse_node.h:191
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
#define Assert(condition)
Definition: c.h:739
#define lfourth(l)
Definition: pg_list.h:210
static int list_length(const List *l)
Definition: pg_list.h:169
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define lthird(l)
Definition: pg_list.h:205
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:215
#define _(x)
Definition: elog.c:87
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:420
List * fields
Definition: parsenodes.h:235
Node * colNameToVar(ParseState *pstate, const char *colname, bool localonly, int location)

◆ transformCurrentOfExpr()

static Node * transformCurrentOfExpr ( ParseState pstate,
CurrentOfExpr cexpr 
)
static

Definition at line 2649 of file parse_expr.c.

References Assert, CurrentOfExpr::cursor_name, CurrentOfExpr::cursor_param, CurrentOfExpr::cvarno, ColumnRef::fields, IsA, list_make1, ColumnRef::location, makeNode, makeString(), ParseState::p_post_columnref_hook, ParseState::p_pre_columnref_hook, ParseState::p_target_rangetblentry, PARAM_EXTERN, Param::paramid, Param::paramkind, Param::paramtype, and RTERangeTablePosn().

Referenced by transformExprRecurse().

2650 {
2651  int sublevels_up;
2652 
2653  /* CURRENT OF can only appear at top level of UPDATE/DELETE */
2654  Assert(pstate->p_target_rangetblentry != NULL);
2655  cexpr->cvarno = RTERangeTablePosn(pstate,
2656  pstate->p_target_rangetblentry,
2657  &sublevels_up);
2658  Assert(sublevels_up == 0);
2659 
2660  /*
2661  * Check to see if the cursor name matches a parameter of type REFCURSOR.
2662  * If so, replace the raw name reference with a parameter reference. (This
2663  * is a hack for the convenience of plpgsql.)
2664  */
2665  if (cexpr->cursor_name != NULL) /* in case already transformed */
2666  {
2667  ColumnRef *cref = makeNode(ColumnRef);
2668  Node *node = NULL;
2669 
2670  /* Build an unqualified ColumnRef with the given name */
2671  cref->fields = list_make1(makeString(cexpr->cursor_name));
2672  cref->location = -1;
2673 
2674  /* See if there is a translation available from a parser hook */
2675  if (pstate->p_pre_columnref_hook != NULL)
2676  node = pstate->p_pre_columnref_hook(pstate, cref);
2677  if (node == NULL && pstate->p_post_columnref_hook != NULL)
2678  node = pstate->p_post_columnref_hook(pstate, cref, NULL);
2679 
2680  /*
2681  * XXX Should we throw an error if we get a translation that isn't a
2682  * refcursor Param? For now it seems best to silently ignore false
2683  * matches.
2684  */
2685  if (node != NULL && IsA(node, Param))
2686  {
2687  Param *p = (Param *) node;
2688 
2689  if (p->paramkind == PARAM_EXTERN &&
2690  p->paramtype == REFCURSOROID)
2691  {
2692  /* Matches, so convert CURRENT OF to a param reference */
2693  cexpr->cursor_name = NULL;
2694  cexpr->cursor_param = p->paramid;
2695  }
2696  }
2697  }
2698 
2699  return (Node *) cexpr;
2700 }
Value * makeString(char *str)
Definition: value.c:53
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
ParamKind paramkind
Definition: primnodes.h:248
Definition: nodes.h:525
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:216
int location
Definition: parsenodes.h:236
#define list_make1(x1)
Definition: pg_list.h:227
char * cursor_name
Definition: primnodes.h:1303
RangeTblEntry * p_target_rangetblentry
Definition: parse_node.h:188
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
int paramid
Definition: primnodes.h:249
int RTERangeTablePosn(ParseState *pstate, RangeTblEntry *rte, int *sublevels_up)
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:215
Oid paramtype
Definition: primnodes.h:250
List * fields
Definition: parsenodes.h:235

◆ transformExpr()

Node* transformExpr ( ParseState pstate,
Node expr,
ParseExprKind  exprKind 
)

Definition at line 144 of file parse_expr.c.

References Assert, EXPR_KIND_NONE, ParseState::p_expr_kind, and transformExprRecurse().

Referenced by cookConstraint(), cookDefault(), DoCopy(), domainAddConstraint(), EvaluateParams(), ExpandIndirectionStar(), findTargetlistEntrySQL99(), interpret_function_parameter_list(), resolve_unique_index_expr(), transformAlterTableStmt(), transformCallStmt(), transformContainerSubscripts(), transformExpressionList(), transformFrameOffset(), transformFuncCall(), transformGroupingFunc(), transformIndexStmt(), transformJoinUsingClause(), transformLimitClause(), transformOnConflictArbiter(), transformPartitionBoundValue(), transformPartitionSpec(), transformRangeFunction(), transformRangeTableFunc(), transformRangeTableSample(), transformTargetEntry(), and transformWhereClause().

145 {
146  Node *result;
147  ParseExprKind sv_expr_kind;
148 
149  /* Save and restore identity of expression type we're parsing */
150  Assert(exprKind != EXPR_KIND_NONE);
151  sv_expr_kind = pstate->p_expr_kind;
152  pstate->p_expr_kind = exprKind;
153 
154  result = transformExprRecurse(pstate, expr);
155 
156  pstate->p_expr_kind = sv_expr_kind;
157 
158  return result;
159 }
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
Definition: nodes.h:525
ParseExprKind
Definition: parse_node.h:33
ParseExprKind p_expr_kind
Definition: parse_node.h:191
#define Assert(condition)
Definition: c.h:739

◆ transformExprRecurse()

static Node * transformExprRecurse ( ParseState pstate,
Node expr 
)
static

Definition at line 162 of file parse_expr.c.

References AEXPR_BETWEEN, AEXPR_BETWEEN_SYM, AEXPR_DISTINCT, AEXPR_ILIKE, AEXPR_IN, AEXPR_LIKE, AEXPR_NOT_BETWEEN, AEXPR_NOT_BETWEEN_SYM, AEXPR_NOT_DISTINCT, AEXPR_NULLIF, AEXPR_OF, AEXPR_OP, AEXPR_OP_ALL, AEXPR_OP_ANY, AEXPR_PAREN, AEXPR_SIMILAR, NamedArgExpr::arg, NullTest::arg, NullTest::argisrow, check_stack_depth(), elog, emit_precedence_warnings(), ereport, errcode(), errmsg(), ERROR, exprType(), InvalidOid, A_Expr::kind, A_Expr::lexpr, A_Const::location, NullTest::location, make_const(), nodeTag, operator_precedence_warning, parser_errposition(), PREC_GROUP_POSTFIX_IS, T_A_ArrayExpr, T_A_Const, T_A_Expr, T_A_Indirection, T_BooleanTest, T_BoolExpr, T_CaseExpr, T_CaseTestExpr, T_CoalesceExpr, T_CollateClause, T_ColumnRef, T_CurrentOfExpr, T_FuncCall, T_GroupingFunc, T_MinMaxExpr, T_MultiAssignRef, T_NamedArgExpr, T_NullTest, T_ParamRef, T_RowExpr, T_SetToDefault, T_SQLValueFunction, T_SubLink, T_TypeCast, T_Var, T_XmlExpr, T_XmlSerialize, transformAExprBetween(), transformAExprDistinct(), transformAExprIn(), transformAExprNullIf(), transformAExprOf(), transformAExprOp(), transformAExprOpAll(), transformAExprOpAny(), transformArrayExpr(), transformBooleanTest(), transformBoolExpr(), transformCaseExpr(), transformCoalesceExpr(), transformCollateClause(), transformColumnRef(), transformCurrentOfExpr(), transformFuncCall(), transformGroupingFunc(), transformIndirection(), transformMinMaxExpr(), transformMultiAssignRef(), transformParamRef(), transformRowExpr(), transformSQLValueFunction(), transformSubLink(), transformTypeCast(), transformXmlExpr(), transformXmlSerialize(), type_is_rowtype(), A_Const::val, and val.

Referenced by make_nulltest_from_distinct(), transformAExprBetween(), transformAExprDistinct(), transformAExprIn(), transformAExprNullIf(), transformAExprOf(), transformAExprOp(), transformAExprOpAll(), transformAExprOpAny(), transformArrayExpr(), transformBooleanTest(), transformBoolExpr(), transformCaseExpr(), transformCoalesceExpr(), transformCollateClause(), transformExpr(), transformFuncCall(), transformIndirection(), transformMinMaxExpr(), transformMultiAssignRef(), transformSubLink(), transformTypeCast(), transformXmlExpr(), and transformXmlSerialize().

163 {
164  Node *result;
165 
166  if (expr == NULL)
167  return NULL;
168 
169  /* Guard against stack overflow due to overly complex expressions */
171 
172  switch (nodeTag(expr))
173  {
174  case T_ColumnRef:
175  result = transformColumnRef(pstate, (ColumnRef *) expr);
176  break;
177 
178  case T_ParamRef:
179  result = transformParamRef(pstate, (ParamRef *) expr);
180  break;
181 
182  case T_A_Const:
183  {
184  A_Const *con = (A_Const *) expr;
185  Value *val = &con->val;
186 
187  result = (Node *) make_const(pstate, val, con->location);
188  break;
189  }
190 
191  case T_A_Indirection:
192  result = transformIndirection(pstate, (A_Indirection *) expr);
193  break;
194 
195  case T_A_ArrayExpr:
196  result = transformArrayExpr(pstate, (A_ArrayExpr *) expr,
197  InvalidOid, InvalidOid, -1);
198  break;
199 
200  case T_TypeCast:
201  result = transformTypeCast(pstate, (TypeCast *) expr);
202  break;
203 
204  case T_CollateClause:
205  result = transformCollateClause(pstate, (CollateClause *) expr);
206  break;
207 
208  case T_A_Expr:
209  {
210  A_Expr *a = (A_Expr *) expr;
211 
212  switch (a->kind)
213  {
214  case AEXPR_OP:
215  result = transformAExprOp(pstate, a);
216  break;
217  case AEXPR_OP_ANY:
218  result = transformAExprOpAny(pstate, a);
219  break;
220  case AEXPR_OP_ALL:
221  result = transformAExprOpAll(pstate, a);
222  break;
223  case AEXPR_DISTINCT:
224  case AEXPR_NOT_DISTINCT:
225  result = transformAExprDistinct(pstate, a);
226  break;
227  case AEXPR_NULLIF:
228  result = transformAExprNullIf(pstate, a);
229  break;
230  case AEXPR_OF:
231  result = transformAExprOf(pstate, a);
232  break;
233  case AEXPR_IN:
234  result = transformAExprIn(pstate, a);
235  break;
236  case AEXPR_LIKE:
237  case AEXPR_ILIKE:
238  case AEXPR_SIMILAR:
239  /* we can transform these just like AEXPR_OP */
240  result = transformAExprOp(pstate, a);
241  break;
242  case AEXPR_BETWEEN:
243  case AEXPR_NOT_BETWEEN:
244  case AEXPR_BETWEEN_SYM:
246  result = transformAExprBetween(pstate, a);
247  break;
248  case AEXPR_PAREN:
249  result = transformExprRecurse(pstate, a->lexpr);
250  break;
251  default:
252  elog(ERROR, "unrecognized A_Expr kind: %d", a->kind);
253  result = NULL; /* keep compiler quiet */
254  break;
255  }
256  break;
257  }
258 
259  case T_BoolExpr:
260  result = transformBoolExpr(pstate, (BoolExpr *) expr);
261  break;
262 
263  case T_FuncCall:
264  result = transformFuncCall(pstate, (FuncCall *) expr);
265  break;
266 
267  case T_MultiAssignRef:
268  result = transformMultiAssignRef(pstate, (MultiAssignRef *) expr);
269  break;
270 
271  case T_GroupingFunc:
272  result = transformGroupingFunc(pstate, (GroupingFunc *) expr);
273  break;
274 
275  case T_NamedArgExpr:
276  {
277  NamedArgExpr *na = (NamedArgExpr *) expr;
278 
279  na->arg = (Expr *) transformExprRecurse(pstate, (Node *) na->arg);
280  result = expr;
281  break;
282  }
283 
284  case T_SubLink:
285  result = transformSubLink(pstate, (SubLink *) expr);
286  break;
287 
288  case T_CaseExpr:
289  result = transformCaseExpr(pstate, (CaseExpr *) expr);
290  break;
291 
292  case T_RowExpr:
293  result = transformRowExpr(pstate, (RowExpr *) expr, false);
294  break;
295 
296  case T_CoalesceExpr:
297  result = transformCoalesceExpr(pstate, (CoalesceExpr *) expr);
298  break;
299 
300  case T_MinMaxExpr:
301  result = transformMinMaxExpr(pstate, (MinMaxExpr *) expr);
302  break;
303 
304  case T_SQLValueFunction:
305  result = transformSQLValueFunction(pstate,
306  (SQLValueFunction *) expr);
307  break;
308 
309  case T_XmlExpr:
310  result = transformXmlExpr(pstate, (XmlExpr *) expr);
311  break;
312 
313  case T_XmlSerialize:
314  result = transformXmlSerialize(pstate, (XmlSerialize *) expr);
315  break;
316 
317  case T_NullTest:
318  {
319  NullTest *n = (NullTest *) expr;
320 
323  (Node *) n->arg, NULL,
324  n->location);
325 
326  n->arg = (Expr *) transformExprRecurse(pstate, (Node *) n->arg);
327  /* the argument can be any type, so don't coerce it */
328  n->argisrow = type_is_rowtype(exprType((Node *) n->arg));
329  result = expr;
330  break;
331  }
332 
333  case T_BooleanTest:
334  result = transformBooleanTest(pstate, (BooleanTest *) expr);
335  break;
336 
337  case T_CurrentOfExpr:
338  result = transformCurrentOfExpr(pstate, (CurrentOfExpr *) expr);
339  break;
340 
341  /*
342  * In all places where DEFAULT is legal, the caller should have
343  * processed it rather than passing it to transformExpr().
344  */
345  case T_SetToDefault:
346  ereport(ERROR,
347  (errcode(ERRCODE_SYNTAX_ERROR),
348  errmsg("DEFAULT is not allowed in this context"),
349  parser_errposition(pstate,
350  ((SetToDefault *) expr)->location)));
351  break;
352 
353  /*
354  * CaseTestExpr doesn't require any processing; it is only
355  * injected into parse trees in a fully-formed state.
356  *
357  * Ordinarily we should not see a Var here, but it is convenient
358  * for transformJoinUsingClause() to create untransformed operator
359  * trees containing already-transformed Vars. The best
360  * alternative would be to deconstruct and reconstruct column
361  * references, which seems expensively pointless. So allow it.
362  */
363  case T_CaseTestExpr:
364  case T_Var:
365  {
366  result = (Node *) expr;
367  break;
368  }
369 
370  default:
371  /* should not reach here */
372  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
373  result = NULL; /* keep compiler quiet */
374  break;
375  }
376 
377  return result;
378 }
static Node * transformAExprDistinct(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1067
static Node * transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
Definition: parse_expr.c:2256
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
static Node * transformIndirection(ParseState *pstate, A_Indirection *ind)
Definition: parse_expr.c:433
static Node * transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr)
Definition: parse_expr.c:2649
static Node * transformAExprOpAny(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1021
A_Expr_Kind kind
Definition: parsenodes.h:275
#define PREC_GROUP_POSTFIX_IS
Definition: parse_expr.c:49
static Node * transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
Definition: parse_expr.c:2335
static Node * transformAExprNullIf(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1123
static Node * transformSubLink(ParseState *pstate, SubLink *sublink)
Definition: parse_expr.c:1848
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
Const * make_const(ParseState *pstate, Value *value, int location)
Definition: parse_node.c:476
static Node * transformBooleanTest(ParseState *pstate, BooleanTest *b)
Definition: parse_expr.c:2604
static Node * transformXmlExpr(ParseState *pstate, XmlExpr *x)
Definition: parse_expr.c:2427
static Node * transformCoalesceExpr(ParseState *pstate, CoalesceExpr *c)
Definition: parse_expr.c:2286
#define ERROR
Definition: elog.h:43
static Node * transformBoolExpr(ParseState *pstate, BoolExpr *a)
Definition: parse_expr.c:1480
Expr * arg
Definition: primnodes.h:1205
static Node * transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, Oid array_type, Oid element_type, int32 typmod)
Definition: parse_expr.c:2098
static Node * transformAExprOpAll(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1044
static Node * transformFuncCall(ParseState *pstate, FuncCall *fn)
Definition: parse_expr.c:1516
void check_stack_depth(void)
Definition: postgres.c:3302
static Node * transformParamRef(ParseState *pstate, ParamRef *pref)
Definition: parse_expr.c:883
static Node * transformAExprOf(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1169
bool type_is_rowtype(Oid typid)
Definition: lsyscache.c:2433
#define ereport(elevel, rest)
Definition: elog.h:141
Node * lexpr
Definition: parsenodes.h:277
static Node * transformAExprOp(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:920
Definition: nodes.h:151
static Node * transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref)
Definition: parse_expr.c:1561
static Node * transformCollateClause(ParseState *pstate, CollateClause *c)
Definition: parse_expr.c:2834
Node * transformGroupingFunc(ParseState *pstate, GroupingFunc *p)
Definition: parse_agg.c:247
bool operator_precedence_warning
Definition: parse_expr.c:42
static void emit_precedence_warnings(ParseState *pstate, int opgroup, const char *opname, Node *lchild, Node *rchild, int location)
Definition: parse_expr.c:3422
#define InvalidOid
Definition: postgres_ext.h:36
Expr * arg
Definition: primnodes.h:484
int location
Definition: parsenodes.h:289
Definition: value.h:42
int location
Definition: primnodes.h:1208
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
static Node * transformCaseExpr(ParseState *pstate, CaseExpr *c)
Definition: parse_expr.c:1708
#define nodeTag(nodeptr)
Definition: nodes.h:530
static Node * transformTypeCast(ParseState *pstate, TypeCast *tc)
Definition: parse_expr.c:2741
static Node * transformColumnRef(ParseState *pstate, ColumnRef *cref)
Definition: parse_expr.c:507
int errmsg(const char *fmt,...)
Definition: elog.c:822
static Node * transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
Definition: parse_expr.c:2561
#define elog(elevel,...)
Definition: elog.h:228
static Node * transformSQLValueFunction(ParseState *pstate, SQLValueFunction *svf)
Definition: parse_expr.c:2374
bool argisrow
Definition: primnodes.h:1207
Value val
Definition: parsenodes.h:288
long val
Definition: informix.c:664
static Node * transformAExprBetween(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1370
static Node * transformAExprIn(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1210

◆ transformFuncCall()

static Node * transformFuncCall ( ParseState pstate,
FuncCall fn 
)
static

Definition at line 1516 of file parse_expr.c.

References FuncCall::agg_order, FuncCall::agg_within_group, generate_unaccent_rules::args, FuncCall::args, Assert, EXPR_KIND_ORDER_BY, FuncCall::funcname, lappend(), lfirst, FuncCall::location, NIL, SortBy::node, ParseState::p_last_srf, ParseFuncOrColumn(), transformExpr(), and transformExprRecurse().

Referenced by transformExprRecurse().

1517 {
1518  Node *last_srf = pstate->p_last_srf;
1519  List *targs;
1520  ListCell *args;
1521 
1522  /* Transform the list of arguments ... */
1523  targs = NIL;
1524  foreach(args, fn->args)
1525  {
1526  targs = lappend(targs, transformExprRecurse(pstate,
1527  (Node *) lfirst(args)));
1528  }
1529 
1530  /*
1531  * When WITHIN GROUP is used, we treat its ORDER BY expressions as
1532  * additional arguments to the function, for purposes of function lookup
1533  * and argument type coercion. So, transform each such expression and add
1534  * them to the targs list. We don't explicitly mark where each argument
1535  * came from, but ParseFuncOrColumn can tell what's what by reference to
1536  * list_length(fn->agg_order).
1537  */
1538  if (fn->agg_within_group)
1539  {
1540  Assert(fn->agg_order != NIL);
1541  foreach(args, fn->agg_order)
1542  {
1543  SortBy *arg = (SortBy *) lfirst(args);
1544 
1545  targs = lappend(targs, transformExpr(pstate, arg->node,
1547  }
1548  }
1549 
1550  /* ... and hand off to ParseFuncOrColumn */
1551  return ParseFuncOrColumn(pstate,
1552  fn->funcname,
1553  targs,
1554  last_srf,
1555  fn,
1556  false,
1557  fn->location);
1558 }
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:144
Definition: nodes.h:525
int location
Definition: parsenodes.h:359
List * agg_order
Definition: parsenodes.h:352
Node * ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
Definition: parse_func.c:88
List * lappend(List *list, void *datum)
Definition: list.c:322
Node * p_last_srf
Definition: parse_node.h:209
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
List * args
Definition: parsenodes.h:351
void * arg
List * funcname
Definition: parsenodes.h:350
Node * node
Definition: parsenodes.h:469
bool agg_within_group
Definition: parsenodes.h:354
Definition: pg_list.h:50

◆ transformIndirection()

static Node * transformIndirection ( ParseState pstate,
A_Indirection ind 
)
static

Definition at line 433 of file parse_expr.c.

References A_Indirection::arg, Assert, ereport, errcode(), errmsg(), ERROR, exprLocation(), exprType(), exprTypmod(), i, A_Indirection::indirection, InvalidOid, IsA, lappend(), lfirst, list_make1, NIL, ParseState::p_last_srf, ParseFuncOrColumn(), parser_errposition(), strVal, transformContainerSubscripts(), transformExprRecurse(), and unknown_attribute().

Referenced by transformExprRecurse().

434 {
435  Node *last_srf = pstate->p_last_srf;
436  Node *result = transformExprRecurse(pstate, ind->arg);
437  List *subscripts = NIL;
438  int location = exprLocation(result);
439  ListCell *i;
440 
441  /*
442  * We have to split any field-selection operations apart from
443  * subscripting. Adjacent A_Indices nodes have to be treated as a single
444  * multidimensional subscript operation.
445  */
446  foreach(i, ind->indirection)
447  {
448  Node *n = lfirst(i);
449 
450  if (IsA(n, A_Indices))
451  subscripts = lappend(subscripts, n);
452  else if (IsA(n, A_Star))
453  {
454  ereport(ERROR,
455  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
456  errmsg("row expansion via \"*\" is not supported here"),
457  parser_errposition(pstate, location)));
458  }
459  else
460  {
461  Node *newresult;
462 
463  Assert(IsA(n, String));
464 
465  /* process subscripts before this field selection */
466  if (subscripts)
467  result = (Node *) transformContainerSubscripts(pstate,
468  result,
469  exprType(result),
470  InvalidOid,
471  exprTypmod(result),
472  subscripts,
473  NULL);
474  subscripts = NIL;
475 
476  newresult = ParseFuncOrColumn(pstate,
477  list_make1(n),
478  list_make1(result),
479  last_srf,
480  NULL,
481  false,
482  location);
483  if (newresult == NULL)
484  unknown_attribute(pstate, result, strVal(n), location);
485  result = newresult;
486  }
487  }
488  /* process trailing subscripts, if any */
489  if (subscripts)
490  result = (Node *) transformContainerSubscripts(pstate,
491  result,
492  exprType(result),
493  InvalidOid,
494  exprTypmod(result),
495  subscripts,
496  NULL);
497 
498  return result;
499 }
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
static void unknown_attribute(ParseState *pstate, Node *relref, const char *attname, int location)
Definition: parse_expr.c:387
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1191
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
Definition: nodes.h:525
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
#define list_make1(x1)
Definition: pg_list.h:227
#define ERROR
Definition: elog.h:43
Node * ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
Definition: parse_func.c:88
#define ereport(elevel, rest)
Definition: elog.h:141
List * lappend(List *list, void *datum)
Definition: list.c:322
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, Oid elementType, int32 containerTypMod, List *indirection, Node *assignFrom)
Definition: parse_node.c:297
Node * p_last_srf
Definition: parse_node.h:209
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
List * indirection
Definition: parsenodes.h:406
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822
int i
Definition: pg_list.h:50

◆ transformMinMaxExpr()

static Node * transformMinMaxExpr ( ParseState pstate,
MinMaxExpr m 
)
static

Definition at line 2335 of file parse_expr.c.

References generate_unaccent_rules::args, MinMaxExpr::args, coerce_to_common_type(), IS_GREATEST, lappend(), lfirst, MinMaxExpr::location, makeNode, MinMaxExpr::minmaxtype, NIL, MinMaxExpr::op, select_common_type(), and transformExprRecurse().

Referenced by transformExprRecurse().

2336 {
2337  MinMaxExpr *newm = makeNode(MinMaxExpr);
2338  List *newargs = NIL;
2339  List *newcoercedargs = NIL;
2340  const char *funcname = (m->op == IS_GREATEST) ? "GREATEST" : "LEAST";
2341  ListCell *args;
2342 
2343  newm->op = m->op;
2344  foreach(args, m->args)
2345  {
2346  Node *e = (Node *) lfirst(args);
2347  Node *newe;
2348 
2349  newe = transformExprRecurse(pstate, e);
2350  newargs = lappend(newargs, newe);
2351  }
2352 
2353  newm->minmaxtype = select_common_type(pstate, newargs, funcname, NULL);
2354  /* minmaxcollid and inputcollid will be set by parse_collate.c */
2355 
2356  /* Convert arguments if necessary */
2357  foreach(args, newargs)
2358  {
2359  Node *e = (Node *) lfirst(args);
2360  Node *newe;
2361 
2362  newe = coerce_to_common_type(pstate, e,
2363  newm->minmaxtype,
2364  funcname);
2365  newcoercedargs = lappend(newcoercedargs, newe);
2366  }
2367 
2368  newm->args = newcoercedargs;
2369  newm->location = m->location;
2370  return (Node *) newm;
2371 }
Oid minmaxtype
Definition: primnodes.h:1088
#define NIL
Definition: pg_list.h:65
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
List * args
Definition: primnodes.h:1092
Definition: nodes.h:525
int location
Definition: primnodes.h:1093
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
List * lappend(List *list, void *datum)
Definition: list.c:322
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
e
Definition: preproc-init.c:82
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
MinMaxOp op
Definition: primnodes.h:1091
Definition: pg_list.h:50

◆ transformMultiAssignRef()

static Node * transformMultiAssignRef ( ParseState pstate,
MultiAssignRef maref 
)
static

Definition at line 1561 of file parse_expr.c.

References RowExpr::args, Assert, castNode, MultiAssignRef::colno, count_nonjunk_tlist_entries(), elog, ereport, errcode(), errmsg(), ERROR, TargetEntry::expr, EXPR_KIND_UPDATE_SOURCE, EXPR_SUBLINK, exprCollation(), exprLocation(), exprType(), exprTypmod(), IsA, lappend(), list_delete_ptr(), list_length(), list_nth(), llast, Param::location, RowExpr::location, makeNode, makeTargetEntry(), MULTIEXPR_SUBLINK, MultiAssignRef::ncolumns, NIL, ParseState::p_expr_kind, ParseState::p_multiassign_exprs, PARAM_MULTIEXPR, Param::paramcollid, Param::paramid, Param::paramkind, Param::paramtype, Param::paramtypmod, parser_errposition(), TargetEntry::resjunk, MultiAssignRef::source, SubLink::subLinkId, SubLink::subLinkType, SubLink::subselect, Query::targetList, transformExprRecurse(), and transformRowExpr().

Referenced by transformExprRecurse().

1562 {
1563  SubLink *sublink;
1564  RowExpr *rexpr;
1565  Query *qtree;
1566  TargetEntry *tle;
1567 
1568  /* We should only see this in first-stage processing of UPDATE tlists */
1570 
1571  /* We only need to transform the source if this is the first column */
1572  if (maref->colno == 1)
1573  {
1574  /*
1575  * For now, we only allow EXPR SubLinks and RowExprs as the source of
1576  * an UPDATE multiassignment. This is sufficient to cover interesting
1577  * cases; at worst, someone would have to write (SELECT * FROM expr)
1578  * to expand a composite-returning expression of another form.
1579  */
1580  if (IsA(maref->source, SubLink) &&
1581  ((SubLink *) maref->source)->subLinkType == EXPR_SUBLINK)
1582  {
1583  /* Relabel it as a MULTIEXPR_SUBLINK */
1584  sublink = (SubLink *) maref->source;
1585  sublink->subLinkType = MULTIEXPR_SUBLINK;
1586  /* And transform it */
1587  sublink = (SubLink *) transformExprRecurse(pstate,
1588  (Node *) sublink);
1589 
1590  qtree = castNode(Query, sublink->subselect);
1591 
1592  /* Check subquery returns required number of columns */
1593  if (count_nonjunk_tlist_entries(qtree->targetList) != maref->ncolumns)
1594  ereport(ERROR,
1595  (errcode(ERRCODE_SYNTAX_ERROR),
1596  errmsg("number of columns does not match number of values"),
1597  parser_errposition(pstate, sublink->location)));
1598 
1599  /*
1600  * Build a resjunk tlist item containing the MULTIEXPR SubLink,
1601  * and add it to pstate->p_multiassign_exprs, whence it will later
1602  * get appended to the completed targetlist. We needn't worry
1603  * about selecting a resno for it; transformUpdateStmt will do
1604  * that.
1605  */
1606  tle = makeTargetEntry((Expr *) sublink, 0, NULL, true);
1608  tle);
1609 
1610  /*
1611  * Assign a unique-within-this-targetlist ID to the MULTIEXPR
1612  * SubLink. We can just use its position in the
1613  * p_multiassign_exprs list.
1614  */
1615  sublink->subLinkId = list_length(pstate->p_multiassign_exprs);
1616  }
1617  else if (IsA(maref->source, RowExpr))
1618  {
1619  /* Transform the RowExpr, allowing SetToDefault items */
1620  rexpr = (RowExpr *) transformRowExpr(pstate,
1621  (RowExpr *) maref->source,
1622  true);
1623 
1624  /* Check it returns required number of columns */
1625  if (list_length(rexpr->args) != maref->ncolumns)
1626  ereport(ERROR,
1627  (errcode(ERRCODE_SYNTAX_ERROR),
1628  errmsg("number of columns does not match number of values"),
1629  parser_errposition(pstate, rexpr->location)));
1630 
1631  /*
1632  * Temporarily append it to p_multiassign_exprs, so we can get it
1633  * back when we come back here for additional columns.
1634  */
1635  tle = makeTargetEntry((Expr *) rexpr, 0, NULL, true);
1637  tle);
1638  }
1639  else
1640  ereport(ERROR,
1641  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1642  errmsg("source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"),
1643  parser_errposition(pstate, exprLocation(maref->source))));
1644  }
1645  else
1646  {
1647  /*
1648  * Second or later column in a multiassignment. Re-fetch the
1649  * transformed SubLink or RowExpr, which we assume is still the last
1650  * entry in p_multiassign_exprs.
1651  */
1652  Assert(pstate->p_multiassign_exprs != NIL);
1653  tle = (TargetEntry *) llast(pstate->p_multiassign_exprs);
1654  }
1655 
1656  /*
1657  * Emit the appropriate output expression for the current column
1658  */
1659  if (IsA(tle->expr, SubLink))
1660  {
1661  Param *param;
1662 
1663  sublink = (SubLink *) tle->expr;
1664  Assert(sublink->subLinkType == MULTIEXPR_SUBLINK);
1665  qtree = castNode(Query, sublink->subselect);
1666 
1667  /* Build a Param representing the current subquery output column */
1668  tle = (TargetEntry *) list_nth(qtree->targetList, maref->colno - 1);
1669  Assert(!tle->resjunk);
1670 
1671  param = makeNode(Param);
1672  param->paramkind = PARAM_MULTIEXPR;
1673  param->paramid = (sublink->subLinkId << 16) | maref->colno;
1674  param->paramtype = exprType((Node *) tle->expr);
1675  param->paramtypmod = exprTypmod((Node *) tle->expr);
1676  param->paramcollid = exprCollation((Node *) tle->expr);
1677  param->location = exprLocation((Node *) tle->expr);
1678 
1679  return (Node *) param;
1680  }
1681 
1682  if (IsA(tle->expr, RowExpr))
1683  {
1684  Node *result;
1685 
1686  rexpr = (RowExpr *) tle->expr;
1687 
1688  /* Just extract and return the next element of the RowExpr */
1689  result = (Node *) list_nth(rexpr->args, maref->colno - 1);
1690 
1691  /*
1692  * If we're at the last column, delete the RowExpr from
1693  * p_multiassign_exprs; we don't need it anymore, and don't want it in
1694  * the finished UPDATE tlist.
1695  */
1696  if (maref->colno == maref->ncolumns)
1697  pstate->p_multiassign_exprs =
1698  list_delete_ptr(pstate->p_multiassign_exprs, tle);
1699 
1700  return result;
1701  }
1702 
1703  elog(ERROR, "unexpected expr type in multiassign list");
1704  return NULL; /* keep compiler quiet */
1705 }
#define NIL
Definition: pg_list.h:65
static Node * transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
Definition: parse_expr.c:2256
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:162
List * args
Definition: primnodes.h:1008
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1191
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
#define llast(l)
Definition: pg_list.h:215
ParamKind paramkind
Definition: primnodes.h:248
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
List * p_multiassign_exprs
Definition: parse_node.h:193
List * list_delete_ptr(List *list, void *datum)
Definition: list.c:797
List * targetList
Definition: parsenodes.h:140
bool resjunk
Definition: primnodes.h:1400
#define ERROR
Definition: elog.h:43
Oid paramcollid
Definition: primnodes.h:252
static void * list_nth(const List *list, int n)
Definition: pg_list.h:277
int location
Definition: primnodes.h:253
int location
Definition: primnodes.h:1025
#define ereport(elevel, rest)
Definition: elog.h:141
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:236
List * lappend(List *list, void *datum)
Definition: list.c:322
ParseExprKind p_expr_kind
Definition: parse_node.h:191
int32 paramtypmod
Definition: primnodes.h:251
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
Expr * expr
Definition: primnodes.h:1393
int paramid
Definition: primnodes.h:249
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static int list_length(const List *l)
Definition: pg_list.h:169
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:719
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
int count_nonjunk_tlist_entries(List *tlist)
Definition: tlist.c:208
Oid paramtype
Definition: primnodes.h:250

◆ transformParamRef()

static Node * transformParamRef ( ParseState pstate,
ParamRef pref 
)
static

Definition at line 883 of file parse_expr.c.

References ereport, errcode(), errmsg(), ERROR, ParamRef::location, ParamRef::number, ParseState::p_paramref_hook, and parser_errposition().

Referenced by transformExprRecurse().

884 {
885  Node *result;
886 
887  /*
888  * The core parser knows nothing about Params. If a hook is supplied,
889  * call it. If not, or if the hook returns NULL, throw a generic error.
890  */
891  if (pstate->p_paramref_hook != NULL)
892  result = pstate->p_paramref_hook(pstate, pref);
893  else
894  result = NULL;
895 
896  if (result == NULL)
897  ereport(ERROR,
898  (errcode(ERRCODE_UNDEFINED_PARAMETER),
899  errmsg("there is no parameter $%d", pref->number),
900  parser_errposition(pstate, pref->location)));
901 
902  return result;
903 }
Definition: nodes.h:525
int errcode(int sqlerrcode)
Definition: elog.c:608
#define ERROR
Definition: elog.h:43
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:217
#define ereport(elevel, rest)
Definition: elog.h:141
int number
Definition: parsenodes.h:245
int location
Definition: parsenodes.h:246
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ transformRowExpr()

static Node * transformRowExpr ( ParseState pstate,
RowExpr r,
bool  allowDefault 
)
static

Definition at line 2256 of file parse_expr.c.

References RowExpr::args, COERCE_IMPLICIT_CAST, RowExpr::colnames, lappend(), list_length(), RowExpr::location, makeNode, makeString(), NIL, ParseState::p_expr_kind, pstrdup(), RowExpr::row_format, RowExpr::row_typeid, snprintf, and transformExpressionList().

Referenced by transformExprRecurse(), and transformMultiAssignRef().

2257 {
2258  RowExpr *newr;
2259  char fname[16];
2260  int fnum;
2261 
2262  newr = makeNode(RowExpr);
2263 
2264  /* Transform the field expressions */
2265  newr->args = transformExpressionList(pstate, r->args,
2266  pstate->p_expr_kind, allowDefault);
2267 
2268  /* Barring later casting, we consider the type RECORD */
2269  newr->row_typeid = RECORDOID;
2271 
2272  /* ROW() has anonymous columns, so invent some field names */
2273  newr->colnames = NIL;
2274  for (fnum = 1; fnum <= list_length(newr->args); fnum++)
2275  {
2276  snprintf(fname, sizeof(fname), "f%d", fnum);
2277  newr->colnames = lappend(newr->colnames, makeString(pstrdup(fname)));
2278  }
2279 
2280  newr->location = r->location;
2281 
2282  return (Node *) newr;
2283 }
Value * makeString(char *str)
Definition: value.c:53
#define NIL
Definition: pg_list.h:65
List * args
Definition: primnodes.h:1008
char * pstrdup(const char *in)
Definition: mcxt.c:1186
Definition: nodes.h:525
List * colnames
Definition: primnodes.h:1024
int location
Definition: primnodes.h:1025
List * lappend(List *list, void *datum)
Definition: list.c:322
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
Definition: parse_target.c:229
ParseExprKind p_expr_kind
Definition: parse_node.h:191
#define makeNode(_type_)
Definition: nodes.h:573
Oid row_typeid
Definition: primnodes.h:1009
static int list_length(const List *l)
Definition: pg_list.h:169
CoercionForm row_format
Definition: primnodes.h:1023
#define snprintf
Definition: port.h:192

◆ transformSQLValueFunction()

static Node * transformSQLValueFunction ( ParseState pstate,
SQLValueFunction svf 
)
static

Definition at line 2374 of file parse_expr.c.

References anytime_typmod_check(), anytimestamp_typmod_check(), SQLValueFunction::op, SVFOP_CURRENT_CATALOG, SVFOP_CURRENT_DATE, SVFOP_CURRENT_ROLE, SVFOP_CURRENT_SCHEMA, SVFOP_CURRENT_TIME, SVFOP_CURRENT_TIME_N, SVFOP_CURRENT_TIMESTAMP, SVFOP_CURRENT_TIMESTAMP_N, SVFOP_CURRENT_USER, SVFOP_LOCALTIME, SVFOP_LOCALTIME_N, SVFOP_LOCALTIMESTAMP, SVFOP_LOCALTIMESTAMP_N, SVFOP_SESSION_USER, SVFOP_USER, SQLValueFunction::type, and SQLValueFunction::typmod.

Referenced by transformExprRecurse().

2375 {
2376  /*
2377  * All we need to do is insert the correct result type and (where needed)
2378  * validate the typmod, so we just modify the node in-place.
2379  */
2380  switch (svf->op)
2381  {
2382  case SVFOP_CURRENT_DATE:
2383  svf->type = DATEOID;
2384  break;
2385  case SVFOP_CURRENT_TIME:
2386  svf->type = TIMETZOID;
2387  break;
2388  case SVFOP_CURRENT_TIME_N:
2389  svf->type = TIMETZOID;
2390  svf->typmod = anytime_typmod_check(true, svf->typmod);
2391  break;
2393  svf->type = TIMESTAMPTZOID;
2394  break;
2396  svf->type = TIMESTAMPTZOID;
2397  svf->typmod = anytimestamp_typmod_check(true, svf->typmod);
2398  break;
2399  case SVFOP_LOCALTIME:
2400  svf->type = TIMEOID;
2401  break;
2402  case SVFOP_LOCALTIME_N:
2403  svf->type = TIMEOID;
2404  svf->typmod = anytime_typmod_check(false, svf->typmod);
2405  break;
2406  case SVFOP_LOCALTIMESTAMP:
2407  svf->type = TIMESTAMPOID;
2408  break;
2410  svf->type = TIMESTAMPOID;
2411  svf->typmod = anytimestamp_typmod_check(false, svf->typmod);
2412  break;
2413  case SVFOP_CURRENT_ROLE:
2414  case SVFOP_CURRENT_USER:
2415  case SVFOP_USER:
2416  case SVFOP_SESSION_USER:
2417  case SVFOP_CURRENT_CATALOG:
2418  case SVFOP_CURRENT_SCHEMA:
2419  svf->type = NAMEOID;
2420  break;
2421  }
2422 
2423  return (Node *) svf;
2424 }
int32 anytime_typmod_check(bool istz, int32 typmod)
Definition: date.c:67
Definition: nodes.h:525
SQLValueFunctionOp op
Definition: primnodes.h:1129
int32 anytimestamp_typmod_check(bool istz, int32 typmod)
Definition: timestamp.c:101

◆ transformSubLink()

static Node * transformSubLink ( ParseState pstate,
SubLink sublink 
)
static

Definition at line 1848 of file parse_expr.c.

References _, ARRAY_SUBLINK, Assert, CMD_SELECT, Query::commandType, count_nonjunk_tlist_entries(), elog, emit_precedence_warnings(), ereport, errcode(), errmsg(), errmsg_internal(), ERROR, EXISTS_SUBLINK, TargetEntry::expr, EXPR_KIND_ALTER_COL_TRANSFORM, EXPR_KIND_CALL_ARGUMENT, EXPR_KIND_CHECK_CONSTRAINT, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_COPY_WHERE, EXPR_KIND_DISTINCT_ON, EXPR_KIND_DOMAIN_CHECK, EXPR_KIND_EXECUTE_PARAMETER, EXPR_KIND_FILTER, EXPR_KIND_FROM_FUNCTION, EXPR_KIND_FROM_SUBSELECT, EXPR_KIND_FUNCTION_DEFAULT, EXPR_KIND_GENERATED_COLUMN, EXPR_KIND_GROUP_BY, EXPR_KIND_HAVING, EXPR_KIND_INDEX_EXPRESSION, EXPR_KIND_INDEX_PREDICATE, EXPR_KIND_INSERT_TARGET, EXPR_KIND_JOIN_ON, EXPR_KIND_JOIN_USING, EXPR_KIND_LIMIT, EXPR_KIND_NONE, EXPR_KIND_OFFSET, EXPR_KIND_ORDER_BY, EXPR_KIND_OTHER, EXPR_KIND_PARTITION_BOUND, EXPR_KIND_PARTITION_EXPRESSION, EXPR_KIND_POLICY, EXPR_KIND_RETURNING, EXPR_KIND_SELECT_TARGET, EXPR_KIND_TRIGGER_WHEN, EXPR_KIND_UPDATE_SOURCE, EXPR_KIND_UPDATE_TARGET, EXPR_KIND_VALUES, EXPR_KIND_VALUES_SINGLE, EXPR_KIND_WHERE, EXPR_KIND_WINDOW_FRAME_GROUPS, EXPR_KIND_WINDOW_FRAME_RANGE, EXPR_KIND_WINDOW_FRAME_ROWS, EXPR_KIND_WINDOW_ORDER, EXPR_KIND_WINDOW_PARTITION, EXPR_SUBLINK, exprCollation(), exprType(), exprTypmod(), IsA, lappend(), lfirst, list_length(), list_make1, llast, Param::location, SubLink::location, make_row_comparison_op(), makeNode, makeString(), MULTIEXPR_SUBLINK, NIL, operator_precedence_warning, SubLink::operName, ParseState::p_expr_kind, ParseState::p_hasSubLinks, PARAM_SUBLINK, Param::paramcollid, Param::paramid, Param::paramkind, Param::paramtype, Param::paramtypmod, parse_sub_analyze(), parser_errposition(), PREC_GROUP_IN, PREC_GROUP_POSTFIX_OP, TargetEntry::resjunk, TargetEntry::resno, strVal, SubLink::subLinkType, SubLink::subselect, Query::targetList, SubLink::testexpr, and transformExprRecurse().

Referenced by transformExprRecurse().

1849 {
1850  Node *result = (Node *) sublink;
1851  Query *qtree;
1852  const char *err;
1853 
1854  /*
1855  * Check to see if the sublink is in an invalid place within the query. We
1856  * allow sublinks everywhere in SELECT/INSERT/UPDATE/DELETE, but generally
1857  * not in utility statements.
1858  */
1859  err = NULL;
1860  switch (pstate->p_expr_kind)
1861  {
1862  case EXPR_KIND_NONE:
1863  Assert(false); /* can't happen */
1864  break;
1865  case EXPR_KIND_OTHER:
1866  /* Accept sublink here; caller must throw error if wanted */
1867  break;
1868  case EXPR_KIND_JOIN_ON:
1869  case EXPR_KIND_JOIN_USING:
1872  case EXPR_KIND_WHERE:
1873  case EXPR_KIND_POLICY:
1874  case EXPR_KIND_HAVING:
1875  case EXPR_KIND_FILTER:
1885  case EXPR_KIND_GROUP_BY:
1886  case EXPR_KIND_ORDER_BY:
1887  case EXPR_KIND_DISTINCT_ON:
1888  case EXPR_KIND_LIMIT:
1889  case EXPR_KIND_OFFSET:
1890  case EXPR_KIND_RETURNING:
1891  case EXPR_KIND_VALUES:
1893  /* okay */
1894  break;
1897  err = _("cannot use subquery in check constraint");
1898  break;
1901  err = _("cannot use subquery in DEFAULT expression");
1902  break;
1904  err = _("cannot use subquery in index expression");
1905  break;
1907  err = _("cannot use subquery in index predicate");
1908  break;
1910  err = _("cannot use subquery in transform expression");
1911  break;
1913  err = _("cannot use subquery in EXECUTE parameter");
1914  break;
1916  err = _("cannot use subquery in trigger WHEN condition");
1917  break;
1919  err = _("cannot use subquery in partition bound");
1920  break;
1922  err = _("cannot use subquery in partition key expression");
1923  break;
1925  err = _("cannot use subquery in CALL argument");
1926  break;
1927  case EXPR_KIND_COPY_WHERE:
1928  err = _("cannot use subquery in COPY FROM WHERE condition");
1929  break;
1931  err = _("cannot use subquery in column generation expression");
1932  break;
1933 
1934  /*
1935  * There is intentionally no default: case here, so that the
1936  * compiler will warn if we add a new ParseExprKind without
1937  * extending this switch. If we do see an unrecognized value at