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.

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 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 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, ParseNamespaceItem *nsitem, int sublevels_up, 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)
 
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 Transform_null_equals = false
 

Function Documentation

◆ exprIsNullConstant()

static bool exprIsNullConstant ( Node arg)
static

Definition at line 831 of file parse_expr.c.

832 {
833  if (arg && IsA(arg, A_Const))
834  {
835  A_Const *con = (A_Const *) arg;
836 
837  if (con->isnull)
838  return true;
839  }
840  return false;
841 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:162
void * arg
bool isnull
Definition: parsenodes.h:326

References arg, IsA, and A_Const::isnull.

Referenced by transformAExprDistinct(), and transformAExprOp().

◆ make_distinct_op()

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

Definition at line 2889 of file parse_expr.c.

2891 {
2892  Expr *result;
2893 
2894  result = make_op(pstate, opname, ltree, rtree,
2895  pstate->p_last_srf, location);
2896  if (((OpExpr *) result)->opresulttype != BOOLOID)
2897  ereport(ERROR,
2898  (errcode(ERRCODE_DATATYPE_MISMATCH),
2899  errmsg("IS DISTINCT FROM requires = operator to yield boolean"),
2900  parser_errposition(pstate, location)));
2901  if (((OpExpr *) result)->opretset)
2902  ereport(ERROR,
2903  (errcode(ERRCODE_DATATYPE_MISMATCH),
2904  /* translator: %s is name of a SQL construct, eg NULLIF */
2905  errmsg("%s must not return a set", "IS DISTINCT FROM"),
2906  parser_errposition(pstate, location)));
2907 
2908  /*
2909  * We rely on DistinctExpr and OpExpr being same struct
2910  */
2911  NodeSetTag(result, T_DistinctExpr);
2912 
2913  return result;
2914 }
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
#define NodeSetTag(nodeptr, t)
Definition: nodes.h:160
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Definition: parse_oper.c:672
Node * p_last_srf
Definition: parse_node.h:215
Definition: ltree.h:43

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

Referenced by make_row_distinct_op(), and transformAExprDistinct().

◆ make_nulltest_from_distinct()

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

Definition at line 2922 of file parse_expr.c.

2923 {
2924  NullTest *nt = makeNode(NullTest);
2925 
2926  nt->arg = (Expr *) transformExprRecurse(pstate, arg);
2927  /* the argument can be any type, so don't coerce it */
2928  if (distincta->kind == AEXPR_NOT_DISTINCT)
2929  nt->nulltesttype = IS_NULL;
2930  else
2931  nt->nulltesttype = IS_NOT_NULL;
2932  /* argisrow = false is correct whether or not arg is composite */
2933  nt->argisrow = false;
2934  nt->location = distincta->location;
2935  return (Node *) nt;
2936 }
#define makeNode(_type_)
Definition: nodes.h:159
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
Definition: parse_expr.c:110
@ AEXPR_NOT_DISTINCT
Definition: parsenodes.h:280
@ IS_NULL
Definition: primnodes.h:1359
@ IS_NOT_NULL
Definition: primnodes.h:1359
int location
Definition: parsenodes.h:301
A_Expr_Kind kind
Definition: parsenodes.h:297
Definition: nodes.h:112
NullTestType nulltesttype
Definition: primnodes.h:1366
int location
Definition: primnodes.h:1368
bool argisrow
Definition: primnodes.h:1367
Expr * arg
Definition: primnodes.h:1365

References AEXPR_NOT_DISTINCT, arg, 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().

◆ make_row_comparison_op()

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

Definition at line 2643 of file parse_expr.c.

2645 {
2646  RowCompareExpr *rcexpr;
2647  RowCompareType rctype;
2648  List *opexprs;
2649  List *opnos;
2650  List *opfamilies;
2651  ListCell *l,
2652  *r;
2653  List **opinfo_lists;
2654  Bitmapset *strats;
2655  int nopers;
2656  int i;
2657 
2658  nopers = list_length(largs);
2659  if (nopers != list_length(rargs))
2660  ereport(ERROR,
2661  (errcode(ERRCODE_SYNTAX_ERROR),
2662  errmsg("unequal number of entries in row expressions"),
2663  parser_errposition(pstate, location)));
2664 
2665  /*
2666  * We can't compare zero-length rows because there is no principled basis
2667  * for figuring out what the operator is.
2668  */
2669  if (nopers == 0)
2670  ereport(ERROR,
2671  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2672  errmsg("cannot compare rows of zero length"),
2673  parser_errposition(pstate, location)));
2674 
2675  /*
2676  * Identify all the pairwise operators, using make_op so that behavior is
2677  * the same as in the simple scalar case.
2678  */
2679  opexprs = NIL;
2680  forboth(l, largs, r, rargs)
2681  {
2682  Node *larg = (Node *) lfirst(l);
2683  Node *rarg = (Node *) lfirst(r);
2684  OpExpr *cmp;
2685 
2686  cmp = castNode(OpExpr, make_op(pstate, opname, larg, rarg,
2687  pstate->p_last_srf, location));
2688 
2689  /*
2690  * We don't use coerce_to_boolean here because we insist on the
2691  * operator yielding boolean directly, not via coercion. If it
2692  * doesn't yield bool it won't be in any index opfamilies...
2693  */
2694  if (cmp->opresulttype != BOOLOID)
2695  ereport(ERROR,
2696  (errcode(ERRCODE_DATATYPE_MISMATCH),
2697  errmsg("row comparison operator must yield type boolean, "
2698  "not type %s",
2699  format_type_be(cmp->opresulttype)),
2700  parser_errposition(pstate, location)));
2701  if (expression_returns_set((Node *) cmp))
2702  ereport(ERROR,
2703  (errcode(ERRCODE_DATATYPE_MISMATCH),
2704  errmsg("row comparison operator must not return a set"),
2705  parser_errposition(pstate, location)));
2706  opexprs = lappend(opexprs, cmp);
2707  }
2708 
2709  /*
2710  * If rows are length 1, just return the single operator. In this case we
2711  * don't insist on identifying btree semantics for the operator (but we
2712  * still require it to return boolean).
2713  */
2714  if (nopers == 1)
2715  return (Node *) linitial(opexprs);
2716 
2717  /*
2718  * Now we must determine which row comparison semantics (= <> < <= > >=)
2719  * apply to this set of operators. We look for btree opfamilies
2720  * containing the operators, and see which interpretations (strategy
2721  * numbers) exist for each operator.
2722  */
2723  opinfo_lists = (List **) palloc(nopers * sizeof(List *));
2724  strats = NULL;
2725  i = 0;
2726  foreach(l, opexprs)
2727  {
2728  Oid opno = ((OpExpr *) lfirst(l))->opno;
2729  Bitmapset *this_strats;
2730  ListCell *j;
2731 
2732  opinfo_lists[i] = get_op_btree_interpretation(opno);
2733 
2734  /*
2735  * convert strategy numbers into a Bitmapset to make the intersection
2736  * calculation easy.
2737  */
2738  this_strats = NULL;
2739  foreach(j, opinfo_lists[i])
2740  {
2741  OpBtreeInterpretation *opinfo = lfirst(j);
2742 
2743  this_strats = bms_add_member(this_strats, opinfo->strategy);
2744  }
2745  if (i == 0)
2746  strats = this_strats;
2747  else
2748  strats = bms_int_members(strats, this_strats);
2749  i++;
2750  }
2751 
2752  /*
2753  * If there are multiple common interpretations, we may use any one of
2754  * them ... this coding arbitrarily picks the lowest btree strategy
2755  * number.
2756  */
2757  i = bms_first_member(strats);
2758  if (i < 0)
2759  {
2760  /* No common interpretation, so fail */
2761  ereport(ERROR,
2762  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2763  errmsg("could not determine interpretation of row comparison operator %s",
2764  strVal(llast(opname))),
2765  errhint("Row comparison operators must be associated with btree operator families."),
2766  parser_errposition(pstate, location)));
2767  }
2768  rctype = (RowCompareType) i;
2769 
2770  /*
2771  * For = and <> cases, we just combine the pairwise operators with AND or
2772  * OR respectively.
2773  */
2774  if (rctype == ROWCOMPARE_EQ)
2775  return (Node *) makeBoolExpr(AND_EXPR, opexprs, location);
2776  if (rctype == ROWCOMPARE_NE)
2777  return (Node *) makeBoolExpr(OR_EXPR, opexprs, location);
2778 
2779  /*
2780  * Otherwise we need to choose exactly which opfamily to associate with
2781  * each operator.
2782  */
2783  opfamilies = NIL;
2784  for (i = 0; i < nopers; i++)
2785  {
2786  Oid opfamily = InvalidOid;
2787  ListCell *j;
2788 
2789  foreach(j, opinfo_lists[i])
2790  {
2791  OpBtreeInterpretation *opinfo = lfirst(j);
2792 
2793  if (opinfo->strategy == rctype)
2794  {
2795  opfamily = opinfo->opfamily_id;
2796  break;
2797  }
2798  }
2799  if (OidIsValid(opfamily))
2800  opfamilies = lappend_oid(opfamilies, opfamily);
2801  else /* should not happen */
2802  ereport(ERROR,
2803  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2804  errmsg("could not determine interpretation of row comparison operator %s",
2805  strVal(llast(opname))),
2806  errdetail("There are multiple equally-plausible candidates."),
2807  parser_errposition(pstate, location)));
2808  }
2809 
2810  /*
2811  * Now deconstruct the OpExprs and create a RowCompareExpr.
2812  *
2813  * Note: can't just reuse the passed largs/rargs lists, because of
2814  * possibility that make_op inserted coercion operations.
2815  */
2816  opnos = NIL;
2817  largs = NIL;
2818  rargs = NIL;
2819  foreach(l, opexprs)
2820  {
2821  OpExpr *cmp = (OpExpr *) lfirst(l);
2822 
2823  opnos = lappend_oid(opnos, cmp->opno);
2824  largs = lappend(largs, linitial(cmp->args));
2825  rargs = lappend(rargs, lsecond(cmp->args));
2826  }
2827 
2828  rcexpr = makeNode(RowCompareExpr);
2829  rcexpr->rctype = rctype;
2830  rcexpr->opnos = opnos;
2831  rcexpr->opfamilies = opfamilies;
2832  rcexpr->inputcollids = NIL; /* assign_expr_collations will fix this */
2833  rcexpr->largs = largs;
2834  rcexpr->rargs = rargs;
2835 
2836  return (Node *) rcexpr;
2837 }
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:739
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:906
int bms_first_member(Bitmapset *a)
Definition: bitmapset.c:1000
#define OidIsValid(objectId)
Definition: c.h:711
int errdetail(const char *fmt,...)
Definition: elog.c:1039
int errhint(const char *fmt,...)
Definition: elog.c:1153
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
int j
Definition: isn.c:74
int i
Definition: isn.c:73
List * lappend(List *list, void *datum)
Definition: list.c:338
List * lappend_oid(List *list, Oid datum)
Definition: list.c:374
List * get_op_btree_interpretation(Oid opno)
Definition: lsyscache.c:600
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Definition: makefuncs.c:369
void * palloc(Size size)
Definition: mcxt.c:1199
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:706
#define castNode(_type_, nodeptr)
Definition: nodes.h:180
#define lfirst(lc)
Definition: pg_list.h:170
#define llast(l)
Definition: pg_list.h:196
static int list_length(const List *l)
Definition: pg_list.h:150
#define NIL
Definition: pg_list.h:66
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:465
#define linitial(l)
Definition: pg_list.h:176
#define lsecond(l)
Definition: pg_list.h:181
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
@ AND_EXPR
Definition: primnodes.h:758
@ OR_EXPR
Definition: primnodes.h:758
RowCompareType
Definition: primnodes.h:1242
@ ROWCOMPARE_NE
Definition: primnodes.h:1249
@ ROWCOMPARE_EQ
Definition: primnodes.h:1246
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747
Definition: pg_list.h:52
RowCompareType rctype
Definition: primnodes.h:1255
List * opfamilies
Definition: primnodes.h:1257
List * inputcollids
Definition: primnodes.h:1258
#define strVal(v)
Definition: value.h:82

References AND_EXPR, 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, j, lappend(), lappend_oid(), RowCompareExpr::largs, lfirst, linitial, list_length(), llast, lsecond, make_op(), makeBoolExpr(), makeNode, NIL, OidIsValid, RowCompareExpr::opfamilies, OpBtreeInterpretation::opfamily_id, RowCompareExpr::opnos, 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().

◆ make_row_distinct_op()

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

Definition at line 2845 of file parse_expr.c.

2848 {
2849  Node *result = NULL;
2850  List *largs = lrow->args;
2851  List *rargs = rrow->args;
2852  ListCell *l,
2853  *r;
2854 
2855  if (list_length(largs) != list_length(rargs))
2856  ereport(ERROR,
2857  (errcode(ERRCODE_SYNTAX_ERROR),
2858  errmsg("unequal number of entries in row expressions"),
2859  parser_errposition(pstate, location)));
2860 
2861  forboth(l, largs, r, rargs)
2862  {
2863  Node *larg = (Node *) lfirst(l);
2864  Node *rarg = (Node *) lfirst(r);
2865  Node *cmp;
2866 
2867  cmp = (Node *) make_distinct_op(pstate, opname, larg, rarg, location);
2868  if (result == NULL)
2869  result = cmp;
2870  else
2871  result = (Node *) makeBoolExpr(OR_EXPR,
2872  list_make2(result, cmp),
2873  location);
2874  }
2875 
2876  if (result == NULL)
2877  {
2878  /* zero-length rows? Generate constant FALSE */
2879  result = makeBoolConst(false, false);
2880  }
2881 
2882  return result;
2883 }
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:357
static Expr * make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, int location)
Definition: parse_expr.c:2889
#define list_make2(x1, x2)
Definition: pg_list.h:212
List * args
Definition: primnodes.h:1207

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().

◆ ParseExprKindName()

const char* ParseExprKindName ( ParseExprKind  exprKind)

Definition at line 2946 of file parse_expr.c.

2947 {
2948  switch (exprKind)
2949  {
2950  case EXPR_KIND_NONE:
2951  return "invalid expression context";
2952  case EXPR_KIND_OTHER:
2953  return "extension expression";
2954  case EXPR_KIND_JOIN_ON:
2955  return "JOIN/ON";
2956  case EXPR_KIND_JOIN_USING:
2957  return "JOIN/USING";
2959  return "sub-SELECT in FROM";
2961  return "function in FROM";
2962  case EXPR_KIND_WHERE:
2963  return "WHERE";
2964  case EXPR_KIND_POLICY:
2965  return "POLICY";
2966  case EXPR_KIND_HAVING:
2967  return "HAVING";
2968  case EXPR_KIND_FILTER:
2969  return "FILTER";
2971  return "window PARTITION BY";
2973  return "window ORDER BY";
2975  return "window RANGE";
2977  return "window ROWS";
2979  return "window GROUPS";
2981  return "SELECT";
2983  return "INSERT";
2986  return "UPDATE";
2987  case EXPR_KIND_MERGE_WHEN:
2988  return "MERGE WHEN";
2989  case EXPR_KIND_GROUP_BY:
2990  return "GROUP BY";
2991  case EXPR_KIND_ORDER_BY:
2992  return "ORDER BY";
2993  case EXPR_KIND_DISTINCT_ON:
2994  return "DISTINCT ON";
2995  case EXPR_KIND_LIMIT:
2996  return "LIMIT";
2997  case EXPR_KIND_OFFSET:
2998  return "OFFSET";
2999  case EXPR_KIND_RETURNING:
3000  return "RETURNING";
3001  case EXPR_KIND_VALUES:
3003  return "VALUES";
3006  return "CHECK";
3009  return "DEFAULT";
3011  return "index expression";
3013  return "index predicate";
3015  return "statistics expression";
3017  return "USING";
3019  return "EXECUTE";
3021  return "WHEN";
3023  return "partition bound";
3025  return "PARTITION BY";
3027  return "CALL";
3028  case EXPR_KIND_COPY_WHERE:
3029  return "WHERE";
3031  return "GENERATED AS";
3032  case EXPR_KIND_CYCLE_MARK:
3033  return "CYCLE";
3034 
3035  /*
3036  * There is intentionally no default: case here, so that the
3037  * compiler will warn if we add a new ParseExprKind without
3038  * extending this switch. If we do see an unrecognized value at
3039  * runtime, we'll fall through to the "unrecognized" return.
3040  */
3041  }
3042  return "unrecognized expression kind";
3043 }
@ EXPR_KIND_EXECUTE_PARAMETER
Definition: parse_node.h:75
@ EXPR_KIND_DOMAIN_CHECK
Definition: parse_node.h:68
@ EXPR_KIND_COPY_WHERE
Definition: parse_node.h:81
@ EXPR_KIND_COLUMN_DEFAULT
Definition: parse_node.h:69
@ EXPR_KIND_DISTINCT_ON
Definition: parse_node.h:61
@ EXPR_KIND_MERGE_WHEN
Definition: parse_node.h:58
@ EXPR_KIND_STATS_EXPRESSION
Definition: parse_node.h:73
@ EXPR_KIND_INDEX_EXPRESSION
Definition: parse_node.h:71
@ EXPR_KIND_PARTITION_BOUND
Definition: parse_node.h:78
@ EXPR_KIND_FUNCTION_DEFAULT
Definition: parse_node.h:70
@ EXPR_KIND_WINDOW_FRAME_RANGE
Definition: parse_node.h:51
@ EXPR_KIND_VALUES
Definition: parse_node.h:65
@ EXPR_KIND_FROM_SUBSELECT
Definition: parse_node.h:44
@ EXPR_KIND_POLICY
Definition: parse_node.h:77
@ EXPR_KIND_WINDOW_FRAME_GROUPS
Definition: parse_node.h:53
@ EXPR_KIND_PARTITION_EXPRESSION
Definition: parse_node.h:79
@ EXPR_KIND_JOIN_USING
Definition: parse_node.h:43
@ EXPR_KIND_INDEX_PREDICATE
Definition: parse_node.h:72
@ EXPR_KIND_ORDER_BY
Definition: parse_node.h:60
@ EXPR_KIND_OFFSET
Definition: parse_node.h:63
@ EXPR_KIND_JOIN_ON
Definition: parse_node.h:42
@ EXPR_KIND_HAVING
Definition: parse_node.h:47
@ EXPR_KIND_INSERT_TARGET
Definition: parse_node.h:55
@ EXPR_KIND_ALTER_COL_TRANSFORM
Definition: parse_node.h:74
@ EXPR_KIND_LIMIT
Definition: parse_node.h:62
@ EXPR_KIND_WHERE
Definition: parse_node.h:46
@ EXPR_KIND_UPDATE_TARGET
Definition: parse_node.h:57
@ EXPR_KIND_SELECT_TARGET
Definition: parse_node.h:54
@ EXPR_KIND_RETURNING
Definition: parse_node.h:64
@ EXPR_KIND_GENERATED_COLUMN
Definition: parse_node.h:82
@ EXPR_KIND_NONE
Definition: parse_node.h:40
@ EXPR_KIND_CALL_ARGUMENT
Definition: parse_node.h:80
@ EXPR_KIND_GROUP_BY
Definition: parse_node.h:59
@ EXPR_KIND_OTHER
Definition: parse_node.h:41
@ EXPR_KIND_FROM_FUNCTION
Definition: parse_node.h:45
@ EXPR_KIND_TRIGGER_WHEN
Definition: parse_node.h:76
@ EXPR_KIND_FILTER
Definition: parse_node.h:48
@ EXPR_KIND_UPDATE_SOURCE
Definition: parse_node.h:56
@ EXPR_KIND_CHECK_CONSTRAINT
Definition: parse_node.h:67
@ EXPR_KIND_WINDOW_PARTITION
Definition: parse_node.h:49
@ EXPR_KIND_CYCLE_MARK
Definition: parse_node.h:83
@ EXPR_KIND_WINDOW_FRAME_ROWS
Definition: parse_node.h:52
@ EXPR_KIND_WINDOW_ORDER
Definition: parse_node.h:50
@ EXPR_KIND_VALUES_SINGLE
Definition: parse_node.h:66

References EXPR_KIND_ALTER_COL_TRANSFORM, EXPR_KIND_CALL_ARGUMENT, EXPR_KIND_CHECK_CONSTRAINT, EXPR_KIND_COLUMN_DEFAULT, EXPR_KIND_COPY_WHERE, EXPR_KIND_CYCLE_MARK, 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_MERGE_WHEN, 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_STATS_EXPRESSION, 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().

◆ transformAExprBetween()

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

Definition at line 1204 of file parse_expr.c.

1205 {
1206  Node *aexpr;
1207  Node *bexpr;
1208  Node *cexpr;
1209  Node *result;
1210  Node *sub1;
1211  Node *sub2;
1212  List *args;
1213 
1214  /* Deconstruct A_Expr into three subexprs */
1215  aexpr = a->lexpr;
1216  args = castNode(List, a->rexpr);
1217  Assert(list_length(args) == 2);
1218  bexpr = (Node *) linitial(args);
1219  cexpr = (Node *) lsecond(args);
1220 
1221  /*
1222  * Build the equivalent comparison expression. Make copies of
1223  * multiply-referenced subexpressions for safety. (XXX this is really
1224  * wrong since it results in multiple runtime evaluations of what may be
1225  * volatile expressions ...)
1226  *
1227  * Ideally we would not use hard-wired operators here but instead use
1228  * opclasses. However, mixed data types and other issues make this
1229  * difficult:
1230  * http://archives.postgresql.org/pgsql-hackers/2008-08/msg01142.php
1231  */
1232  switch (a->kind)
1233  {
1234  case AEXPR_BETWEEN:
1236  aexpr, bexpr,
1237  a->location),
1238  makeSimpleA_Expr(AEXPR_OP, "<=",
1239  copyObject(aexpr), cexpr,
1240  a->location));
1241  result = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1242  break;
1243  case AEXPR_NOT_BETWEEN:
1245  aexpr, bexpr,
1246  a->location),
1248  copyObject(aexpr), cexpr,
1249  a->location));
1250  result = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1251  break;
1252  case AEXPR_BETWEEN_SYM:
1254  aexpr, bexpr,
1255  a->location),
1256  makeSimpleA_Expr(AEXPR_OP, "<=",
1257  copyObject(aexpr), cexpr,
1258  a->location));
1259  sub1 = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1261  copyObject(aexpr), copyObject(cexpr),
1262  a->location),
1263  makeSimpleA_Expr(AEXPR_OP, "<=",
1264  copyObject(aexpr), copyObject(bexpr),
1265  a->location));
1266  sub2 = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1267  args = list_make2(sub1, sub2);
1268  result = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1269  break;
1270  case AEXPR_NOT_BETWEEN_SYM:
1272  aexpr, bexpr,
1273  a->location),
1275  copyObject(aexpr), cexpr,
1276  a->location));
1277  sub1 = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1279  copyObject(aexpr), copyObject(cexpr),
1280  a->location),
1282  copyObject(aexpr), copyObject(bexpr),
1283  a->location));
1284  sub2 = (Node *) makeBoolExpr(OR_EXPR, args, a->location);
1285  args = list_make2(sub1, sub2);
1286  result = (Node *) makeBoolExpr(AND_EXPR, args, a->location);
1287  break;
1288  default:
1289  elog(ERROR, "unrecognized A_Expr kind: %d", a->kind);
1290  result = NULL; /* keep compiler quiet */
1291  break;
1292  }
1293 
1294  return transformExprRecurse(pstate, result);
1295 }
int a
Definition: isn.c:69
Assert(fmt[strlen(fmt) - 1] !='\n')
A_Expr * makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
Definition: makefuncs.c:48
#define copyObject(obj)
Definition: nodes.h:227
@ AEXPR_BETWEEN
Definition: parsenodes.h:286
@ AEXPR_BETWEEN_SYM
Definition: parsenodes.h:288
@ AEXPR_NOT_BETWEEN_SYM
Definition: parsenodes.h:289
@ AEXPR_NOT_BETWEEN
Definition: parsenodes.h:287
@ AEXPR_OP
Definition: parsenodes.h:276

References a, AEXPR_BETWEEN, AEXPR_BETWEEN_SYM, AEXPR_NOT_BETWEEN, AEXPR_NOT_BETWEEN_SYM, AEXPR_OP, AND_EXPR, generate_unaccent_rules::args, Assert(), castNode, copyObject, elog(), ERROR, linitial, list_length(), list_make2, lsecond, makeBoolExpr(), makeSimpleA_Expr(), OR_EXPR, and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformAExprDistinct()

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

Definition at line 953 of file parse_expr.c.

954 {
955  Node *lexpr = a->lexpr;
956  Node *rexpr = a->rexpr;
957  Node *result;
958 
959  /*
960  * If either input is an undecorated NULL literal, transform to a NullTest
961  * on the other input. That's simpler to process than a full DistinctExpr,
962  * and it avoids needing to require that the datatype have an = operator.
963  */
964  if (exprIsNullConstant(rexpr))
965  return make_nulltest_from_distinct(pstate, a, lexpr);
966  if (exprIsNullConstant(lexpr))
967  return make_nulltest_from_distinct(pstate, a, rexpr);
968 
969  lexpr = transformExprRecurse(pstate, lexpr);
970  rexpr = transformExprRecurse(pstate, rexpr);
971 
972  if (lexpr && IsA(lexpr, RowExpr) &&
973  rexpr && IsA(rexpr, RowExpr))
974  {
975  /* ROW() op ROW() is handled specially */
976  result = make_row_distinct_op(pstate, a->name,
977  (RowExpr *) lexpr,
978  (RowExpr *) rexpr,
979  a->location);
980  }
981  else
982  {
983  /* Ordinary scalar operator */
984  result = (Node *) make_distinct_op(pstate,
985  a->name,
986  lexpr,
987  rexpr,
988  a->location);
989  }
990 
991  /*
992  * If it's NOT DISTINCT, we first build a DistinctExpr and then stick a
993  * NOT on top.
994  */
995  if (a->kind == AEXPR_NOT_DISTINCT)
996  result = (Node *) makeBoolExpr(NOT_EXPR,
997  list_make1(result),
998  a->location);
999 
1000  return result;
1001 }
static Node * make_nulltest_from_distinct(ParseState *pstate, A_Expr *distincta, Node *arg)
Definition: parse_expr.c:2922
static bool exprIsNullConstant(Node *arg)
Definition: parse_expr.c:831
static Node * make_row_distinct_op(ParseState *pstate, List *opname, RowExpr *lrow, RowExpr *rrow, int location)
Definition: parse_expr.c:2845
#define list_make1(x1)
Definition: pg_list.h:210
@ NOT_EXPR
Definition: primnodes.h:758

References a, AEXPR_NOT_DISTINCT, exprIsNullConstant(), IsA, list_make1, make_distinct_op(), make_nulltest_from_distinct(), make_row_distinct_op(), makeBoolExpr(), NOT_EXPR, and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformAExprIn()

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

Definition at line 1046 of file parse_expr.c.

1047 {
1048  Node *result = NULL;
1049  Node *lexpr;
1050  List *rexprs;
1051  List *rvars;
1052  List *rnonvars;
1053  bool useOr;
1054  ListCell *l;
1055 
1056  /*
1057  * If the operator is <>, combine with AND not OR.
1058  */
1059  if (strcmp(strVal(linitial(a->name)), "<>") == 0)
1060  useOr = false;
1061  else
1062  useOr = true;
1063 
1064  /*
1065  * We try to generate a ScalarArrayOpExpr from IN/NOT IN, but this is only
1066  * possible if there is a suitable array type available. If not, we fall
1067  * back to a boolean condition tree with multiple copies of the lefthand
1068  * expression. Also, any IN-list items that contain Vars are handled as
1069  * separate boolean conditions, because that gives the planner more scope
1070  * for optimization on such clauses.
1071  *
1072  * First step: transform all the inputs, and detect whether any contain
1073  * Vars.
1074  */
1075  lexpr = transformExprRecurse(pstate, a->lexpr);
1076  rexprs = rvars = rnonvars = NIL;
1077  foreach(l, (List *) a->rexpr)
1078  {
1079  Node *rexpr = transformExprRecurse(pstate, lfirst(l));
1080 
1081  rexprs = lappend(rexprs, rexpr);
1082  if (contain_vars_of_level(rexpr, 0))
1083  rvars = lappend(rvars, rexpr);
1084  else
1085  rnonvars = lappend(rnonvars, rexpr);
1086  }
1087 
1088  /*
1089  * ScalarArrayOpExpr is only going to be useful if there's more than one
1090  * non-Var righthand item.
1091  */
1092  if (list_length(rnonvars) > 1)
1093  {
1094  List *allexprs;
1095  Oid scalar_type;
1096  Oid array_type;
1097 
1098  /*
1099  * Try to select a common type for the array elements. Note that
1100  * since the LHS' type is first in the list, it will be preferred when
1101  * there is doubt (eg, when all the RHS items are unknown literals).
1102  *
1103  * Note: use list_concat here not lcons, to avoid damaging rnonvars.
1104  */
1105  allexprs = list_concat(list_make1(lexpr), rnonvars);
1106  scalar_type = select_common_type(pstate, allexprs, NULL, NULL);
1107 
1108  /* We have to verify that the selected type actually works */
1109  if (OidIsValid(scalar_type) &&
1110  !verify_common_type(scalar_type, allexprs))
1111  scalar_type = InvalidOid;
1112 
1113  /*
1114  * Do we have an array type to use? Aside from the case where there
1115  * isn't one, we don't risk using ScalarArrayOpExpr when the common
1116  * type is RECORD, because the RowExpr comparison logic below can cope
1117  * with some cases of non-identical row types.
1118  */
1119  if (OidIsValid(scalar_type) && scalar_type != RECORDOID)
1120  array_type = get_array_type(scalar_type);
1121  else
1122  array_type = InvalidOid;
1123  if (array_type != InvalidOid)
1124  {
1125  /*
1126  * OK: coerce all the right-hand non-Var inputs to the common type
1127  * and build an ArrayExpr for them.
1128  */
1129  List *aexprs;
1130  ArrayExpr *newa;
1131 
1132  aexprs = NIL;
1133  foreach(l, rnonvars)
1134  {
1135  Node *rexpr = (Node *) lfirst(l);
1136 
1137  rexpr = coerce_to_common_type(pstate, rexpr,
1138  scalar_type,
1139  "IN");
1140  aexprs = lappend(aexprs, rexpr);
1141  }
1142  newa = makeNode(ArrayExpr);
1143  newa->array_typeid = array_type;
1144  /* array_collid will be set by parse_collate.c */
1145  newa->element_typeid = scalar_type;
1146  newa->elements = aexprs;
1147  newa->multidims = false;
1148  newa->location = -1;
1149 
1150  result = (Node *) make_scalar_array_op(pstate,
1151  a->name,
1152  useOr,
1153  lexpr,
1154  (Node *) newa,
1155  a->location);
1156 
1157  /* Consider only the Vars (if any) in the loop below */
1158  rexprs = rvars;
1159  }
1160  }
1161 
1162  /*
1163  * Must do it the hard way, ie, with a boolean expression tree.
1164  */
1165  foreach(l, rexprs)
1166  {
1167  Node *rexpr = (Node *) lfirst(l);
1168  Node *cmp;
1169 
1170  if (IsA(lexpr, RowExpr) &&
1171  IsA(rexpr, RowExpr))
1172  {
1173  /* ROW() op ROW() is handled specially */
1174  cmp = make_row_comparison_op(pstate,
1175  a->name,
1176  copyObject(((RowExpr *) lexpr)->args),
1177  ((RowExpr *) rexpr)->args,
1178  a->location);
1179  }
1180  else
1181  {
1182  /* Ordinary scalar operator */
1183  cmp = (Node *) make_op(pstate,
1184  a->name,
1185  copyObject(lexpr),
1186  rexpr,
1187  pstate->p_last_srf,
1188  a->location);
1189  }
1190 
1191  cmp = coerce_to_boolean(pstate, cmp, "IN");
1192  if (result == NULL)
1193  result = cmp;
1194  else
1195  result = (Node *) makeBoolExpr(useOr ? OR_EXPR : AND_EXPR,
1196  list_make2(result, cmp),
1197  a->location);
1198  }
1199 
1200  return result;
1201 }
List * list_concat(List *list1, const List *list2)
Definition: list.c:560
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2745
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
bool verify_common_type(Oid common_type, List *exprs)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
static Node * make_row_comparison_op(ParseState *pstate, List *opname, List *largs, List *rargs, int location)
Definition: parse_expr.c:2643
Expr * make_scalar_array_op(ParseState *pstate, List *opname, bool useOr, Node *ltree, Node *rtree, int location)
Definition: parse_oper.c:783
int location
Definition: primnodes.h:1180
bool multidims
Definition: primnodes.h:1179
Oid array_typeid
Definition: primnodes.h:1175
List * elements
Definition: primnodes.h:1178
Oid element_typeid
Definition: primnodes.h:1177
bool contain_vars_of_level(Node *node, int levelsup)
Definition: var.c:431

References a, 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, get_array_type(), InvalidOid, IsA, lappend(), lfirst, linitial, list_concat(), list_length(), list_make1, list_make2, ArrayExpr::location, make_op(), make_row_comparison_op(), make_scalar_array_op(), makeBoolExpr(), makeNode, ArrayExpr::multidims, NIL, OidIsValid, OR_EXPR, ParseState::p_last_srf, select_common_type(), strVal, transformExprRecurse(), and verify_common_type().

Referenced by transformExprRecurse().

◆ transformAExprNullIf()

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

Definition at line 1004 of file parse_expr.c.

1005 {
1006  Node *lexpr = transformExprRecurse(pstate, a->lexpr);
1007  Node *rexpr = transformExprRecurse(pstate, a->rexpr);
1008  OpExpr *result;
1009 
1010  result = (OpExpr *) make_op(pstate,
1011  a->name,
1012  lexpr,
1013  rexpr,
1014  pstate->p_last_srf,
1015  a->location);
1016 
1017  /*
1018  * The comparison operator itself should yield boolean ...
1019  */
1020  if (result->opresulttype != BOOLOID)
1021  ereport(ERROR,
1022  (errcode(ERRCODE_DATATYPE_MISMATCH),
1023  errmsg("NULLIF requires = operator to yield boolean"),
1024  parser_errposition(pstate, a->location)));
1025  if (result->opretset)
1026  ereport(ERROR,
1027  (errcode(ERRCODE_DATATYPE_MISMATCH),
1028  /* translator: %s is name of a SQL construct, eg NULLIF */
1029  errmsg("%s must not return a set", "NULLIF"),
1030  parser_errposition(pstate, a->location)));
1031 
1032  /*
1033  * ... but the NullIfExpr will yield the first operand's type.
1034  */
1035  result->opresulttype = exprType((Node *) linitial(result->args));
1036 
1037  /*
1038  * We rely on NullIfExpr and OpExpr being the same struct
1039  */
1040  NodeSetTag(result, T_NullIfExpr);
1041 
1042  return (Node *) result;
1043 }
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
bool opretset
Definition: primnodes.h:657
List * args
Definition: primnodes.h:666
Oid opresulttype
Definition: primnodes.h:654

References a, OpExpr::args, ereport, errcode(), errmsg(), ERROR, exprType(), linitial, make_op(), NodeSetTag, OpExpr::opresulttype, OpExpr::opretset, ParseState::p_last_srf, parser_errposition(), and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformAExprOp()

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

Definition at line 844 of file parse_expr.c.

845 {
846  Node *lexpr = a->lexpr;
847  Node *rexpr = a->rexpr;
848  Node *result;
849 
850  /*
851  * Special-case "foo = NULL" and "NULL = foo" for compatibility with
852  * standards-broken products (like Microsoft's). Turn these into IS NULL
853  * exprs. (If either side is a CaseTestExpr, then the expression was
854  * generated internally from a CASE-WHEN expression, and
855  * transform_null_equals does not apply.)
856  */
857  if (Transform_null_equals &&
858  list_length(a->name) == 1 &&
859  strcmp(strVal(linitial(a->name)), "=") == 0 &&
860  (exprIsNullConstant(lexpr) || exprIsNullConstant(rexpr)) &&
861  (!IsA(lexpr, CaseTestExpr) && !IsA(rexpr, CaseTestExpr)))
862  {
863  NullTest *n = makeNode(NullTest);
864 
865  n->nulltesttype = IS_NULL;
866  n->location = a->location;
867 
868  if (exprIsNullConstant(lexpr))
869  n->arg = (Expr *) rexpr;
870  else
871  n->arg = (Expr *) lexpr;
872 
873  result = transformExprRecurse(pstate, (Node *) n);
874  }
875  else if (lexpr && IsA(lexpr, RowExpr) &&
876  rexpr && IsA(rexpr, SubLink) &&
877  ((SubLink *) rexpr)->subLinkType == EXPR_SUBLINK)
878  {
879  /*
880  * Convert "row op subselect" into a ROWCOMPARE sublink. Formerly the
881  * grammar did this, but now that a row construct is allowed anywhere
882  * in expressions, it's easier to do it here.
883  */
884  SubLink *s = (SubLink *) rexpr;
885 
887  s->testexpr = lexpr;
888  s->operName = a->name;
889  s->location = a->location;
890  result = transformExprRecurse(pstate, (Node *) s);
891  }
892  else if (lexpr && IsA(lexpr, RowExpr) &&
893  rexpr && IsA(rexpr, RowExpr))
894  {
895  /* ROW() op ROW() is handled specially */
896  lexpr = transformExprRecurse(pstate, lexpr);
897  rexpr = transformExprRecurse(pstate, rexpr);
898 
899  result = make_row_comparison_op(pstate,
900  a->name,
901  castNode(RowExpr, lexpr)->args,
902  castNode(RowExpr, rexpr)->args,
903  a->location);
904  }
905  else
906  {
907  /* Ordinary scalar operator */
908  Node *last_srf = pstate->p_last_srf;
909 
910  lexpr = transformExprRecurse(pstate, lexpr);
911  rexpr = transformExprRecurse(pstate, rexpr);
912 
913  result = (Node *) make_op(pstate,
914  a->name,
915  lexpr,
916  rexpr,
917  last_srf,
918  a->location);
919  }
920 
921  return result;
922 }
bool Transform_null_equals
Definition: parse_expr.c:42
@ EXPR_SUBLINK
Definition: primnodes.h:828
@ ROWCOMPARE_SUBLINK
Definition: primnodes.h:827

References a, NullTest::arg, generate_unaccent_rules::args, castNode, EXPR_SUBLINK, exprIsNullConstant(), IS_NULL, IsA, linitial, list_length(), SubLink::location, NullTest::location, make_op(), make_row_comparison_op(), makeNode, NullTest::nulltesttype, SubLink::operName, ParseState::p_last_srf, ROWCOMPARE_SUBLINK, strVal, SubLink::subLinkType, SubLink::testexpr, Transform_null_equals, and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformAExprOpAll()

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

Definition at line 939 of file parse_expr.c.

940 {
941  Node *lexpr = transformExprRecurse(pstate, a->lexpr);
942  Node *rexpr = transformExprRecurse(pstate, a->rexpr);
943 
944  return (Node *) make_scalar_array_op(pstate,
945  a->name,
946  false,
947  lexpr,
948  rexpr,
949  a->location);
950 }

References a, make_scalar_array_op(), and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformAExprOpAny()

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

Definition at line 925 of file parse_expr.c.

926 {
927  Node *lexpr = transformExprRecurse(pstate, a->lexpr);
928  Node *rexpr = transformExprRecurse(pstate, a->rexpr);
929 
930  return (Node *) make_scalar_array_op(pstate,
931  a->name,
932  true,
933  lexpr,
934  rexpr,
935  a->location);
936 }

References a, make_scalar_array_op(), and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformArrayExpr()

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

Definition at line 1909 of file parse_expr.c.

1911 {
1912  ArrayExpr *newa = makeNode(ArrayExpr);
1913  List *newelems = NIL;
1914  List *newcoercedelems = NIL;
1915  ListCell *element;
1916  Oid coerce_type;
1917  bool coerce_hard;
1918 
1919  /*
1920  * Transform the element expressions
1921  *
1922  * Assume that the array is one-dimensional unless we find an array-type
1923  * element expression.
1924  */
1925  newa->multidims = false;
1926  foreach(element, a->elements)
1927  {
1928  Node *e = (Node *) lfirst(element);
1929  Node *newe;
1930 
1931  /*
1932  * If an element is itself an A_ArrayExpr, recurse directly so that we
1933  * can pass down any target type we were given.
1934  */
1935  if (IsA(e, A_ArrayExpr))
1936  {
1937  newe = transformArrayExpr(pstate,
1938  (A_ArrayExpr *) e,
1939  array_type,
1940  element_type,
1941  typmod);
1942  /* we certainly have an array here */
1943  Assert(array_type == InvalidOid || array_type == exprType(newe));
1944  newa->multidims = true;
1945  }
1946  else
1947  {
1948  newe = transformExprRecurse(pstate, e);
1949 
1950  /*
1951  * Check for sub-array expressions, if we haven't already found
1952  * one.
1953  */
1954  if (!newa->multidims && type_is_array(exprType(newe)))
1955  newa->multidims = true;
1956  }
1957 
1958  newelems = lappend(newelems, newe);
1959  }
1960 
1961  /*
1962  * Select a target type for the elements.
1963  *
1964  * If we haven't been given a target array type, we must try to deduce a
1965  * common type based on the types of the individual elements present.
1966  */
1967  if (OidIsValid(array_type))
1968  {
1969  /* Caller must ensure array_type matches element_type */
1970  Assert(OidIsValid(element_type));
1971  coerce_type = (newa->multidims ? array_type : element_type);
1972  coerce_hard = true;
1973  }
1974  else
1975  {
1976  /* Can't handle an empty array without a target type */
1977  if (newelems == NIL)
1978  ereport(ERROR,
1979  (errcode(ERRCODE_INDETERMINATE_DATATYPE),
1980  errmsg("cannot determine type of empty array"),
1981  errhint("Explicitly cast to the desired type, "
1982  "for example ARRAY[]::integer[]."),
1983  parser_errposition(pstate, a->location)));
1984 
1985  /* Select a common type for the elements */
1986  coerce_type = select_common_type(pstate, newelems, "ARRAY", NULL);
1987 
1988  if (newa->multidims)
1989  {
1990  array_type = coerce_type;
1991  element_type = get_element_type(array_type);
1992  if (!OidIsValid(element_type))
1993  ereport(ERROR,
1994  (errcode(ERRCODE_UNDEFINED_OBJECT),
1995  errmsg("could not find element type for data type %s",
1996  format_type_be(array_type)),
1997  parser_errposition(pstate, a->location)));
1998  }
1999  else
2000  {
2001  element_type = coerce_type;
2002  array_type = get_array_type(element_type);
2003  if (!OidIsValid(array_type))
2004  ereport(ERROR,
2005  (errcode(ERRCODE_UNDEFINED_OBJECT),
2006  errmsg("could not find array type for data type %s",
2007  format_type_be(element_type)),
2008  parser_errposition(pstate, a->location)));
2009  }
2010  coerce_hard = false;
2011  }
2012 
2013  /*
2014  * Coerce elements to target type
2015  *
2016  * If the array has been explicitly cast, then the elements are in turn
2017  * explicitly coerced.
2018  *
2019  * If the array's type was merely derived from the common type of its
2020  * elements, then the elements are implicitly coerced to the common type.
2021  * This is consistent with other uses of select_common_type().
2022  */
2023  foreach(element, newelems)
2024  {
2025  Node *e = (Node *) lfirst(element);
2026  Node *newe;
2027 
2028  if (coerce_hard)
2029  {
2030  newe = coerce_to_target_type(pstate, e,
2031  exprType(e),
2032  coerce_type,
2033  typmod,
2036  -1);
2037  if (newe == NULL)
2038  ereport(ERROR,
2039  (errcode(ERRCODE_CANNOT_COERCE),
2040  errmsg("cannot cast type %s to %s",
2043  parser_errposition(pstate, exprLocation(e))));
2044  }
2045  else
2046  newe = coerce_to_common_type(pstate, e,
2047  coerce_type,
2048  "ARRAY");
2049  newcoercedelems = lappend(newcoercedelems, newe);
2050  }
2051 
2052  newa->array_typeid = array_type;
2053  /* array_collid will be set by parse_collate.c */
2054  newa->element_typeid = element_type;
2055  newa->elements = newcoercedelems;
2056  newa->location = a->location;
2057 
2058  return (Node *) newa;
2059 }
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2717
#define type_is_array(typid)
Definition: lsyscache.h:206
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1243
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:157
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:78
static Node * transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, Oid array_type, Oid element_type, int32 typmod)
Definition: parse_expr.c:1909
e
Definition: preproc-init.c:82
@ COERCE_EXPLICIT_CAST
Definition: primnodes.h:587
@ COERCION_EXPLICIT
Definition: primnodes.h:569
static chr element(struct vars *v, const chr *startp, const chr *endp)
Definition: regc_locale.c:376

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

Referenced by transformExprRecurse(), and transformTypeCast().

◆ transformBooleanTest()

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

Definition at line 2360 of file parse_expr.c.

2361 {
2362  const char *clausename;
2363 
2364  switch (b->booltesttype)
2365  {
2366  case IS_TRUE:
2367  clausename = "IS TRUE";
2368  break;
2369  case IS_NOT_TRUE:
2370  clausename = "IS NOT TRUE";
2371  break;
2372  case IS_FALSE:
2373  clausename = "IS FALSE";
2374  break;
2375  case IS_NOT_FALSE:
2376  clausename = "IS NOT FALSE";
2377  break;
2378  case IS_UNKNOWN:
2379  clausename = "IS UNKNOWN";
2380  break;
2381  case IS_NOT_UNKNOWN:
2382  clausename = "IS NOT UNKNOWN";
2383  break;
2384  default:
2385  elog(ERROR, "unrecognized booltesttype: %d",
2386  (int) b->booltesttype);
2387  clausename = NULL; /* keep compiler quiet */
2388  }
2389 
2390  b->arg = (Expr *) transformExprRecurse(pstate, (Node *) b->arg);
2391 
2392  b->arg = (Expr *) coerce_to_boolean(pstate,
2393  (Node *) b->arg,
2394  clausename);
2395 
2396  return (Node *) b;
2397 }
int b
Definition: isn.c:70
@ IS_NOT_TRUE
Definition: primnodes.h:1382
@ IS_NOT_FALSE
Definition: primnodes.h:1382
@ IS_NOT_UNKNOWN
Definition: primnodes.h:1382
@ IS_TRUE
Definition: primnodes.h:1382
@ IS_UNKNOWN
Definition: primnodes.h:1382
@ IS_FALSE
Definition: primnodes.h:1382

References b, coerce_to_boolean(), elog(), ERROR, IS_FALSE, IS_NOT_FALSE, IS_NOT_TRUE, IS_NOT_UNKNOWN, IS_TRUE, IS_UNKNOWN, and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformBoolExpr()

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

Definition at line 1298 of file parse_expr.c.

1299 {
1300  List *args = NIL;
1301  const char *opname;
1302  ListCell *lc;
1303 
1304  switch (a->boolop)
1305  {
1306  case AND_EXPR:
1307  opname = "AND";
1308  break;
1309  case OR_EXPR:
1310  opname = "OR";
1311  break;
1312  case NOT_EXPR:
1313  opname = "NOT";
1314  break;
1315  default:
1316  elog(ERROR, "unrecognized boolop: %d", (int) a->boolop);
1317  opname = NULL; /* keep compiler quiet */
1318  break;
1319  }
1320 
1321  foreach(lc, a->args)
1322  {
1323  Node *arg = (Node *) lfirst(lc);
1324 
1325  arg = transformExprRecurse(pstate, arg);
1326  arg = coerce_to_boolean(pstate, arg, opname);
1327  args = lappend(args, arg);
1328  }
1329 
1330  return (Node *) makeBoolExpr(a->boolop, args, a->location);
1331 }

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

Referenced by transformExprRecurse().

◆ transformCaseExpr()

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

Definition at line 1527 of file parse_expr.c.

1528 {
1529  CaseExpr *newc = makeNode(CaseExpr);
1530  Node *last_srf = pstate->p_last_srf;
1531  Node *arg;
1532  CaseTestExpr *placeholder;
1533  List *newargs;
1534  List *resultexprs;
1535  ListCell *l;
1536  Node *defresult;
1537  Oid ptype;
1538 
1539  /* transform the test expression, if any */
1540  arg = transformExprRecurse(pstate, (Node *) c->arg);
1541 
1542  /* generate placeholder for test expression */
1543  if (arg)
1544  {
1545  /*
1546  * If test expression is an untyped literal, force it to text. We have
1547  * to do something now because we won't be able to do this coercion on
1548  * the placeholder. This is not as flexible as what was done in 7.4
1549  * and before, but it's good enough to handle the sort of silly coding
1550  * commonly seen.
1551  */
1552  if (exprType(arg) == UNKNOWNOID)
1553  arg = coerce_to_common_type(pstate, arg, TEXTOID, "CASE");
1554 
1555  /*
1556  * Run collation assignment on the test expression so that we know
1557  * what collation to mark the placeholder with. In principle we could
1558  * leave it to parse_collate.c to do that later, but propagating the
1559  * result to the CaseTestExpr would be unnecessarily complicated.
1560  */
1561  assign_expr_collations(pstate, arg);
1562 
1563  placeholder = makeNode(CaseTestExpr);
1564  placeholder->typeId = exprType(arg);
1565  placeholder->typeMod = exprTypmod(arg);
1566  placeholder->collation = exprCollation(arg);
1567  }
1568  else
1569  placeholder = NULL;
1570 
1571  newc->arg = (Expr *) arg;
1572 
1573  /* transform the list of arguments */
1574  newargs = NIL;
1575  resultexprs = NIL;
1576  foreach(l, c->args)
1577  {
1578  CaseWhen *w = lfirst_node(CaseWhen, l);
1579  CaseWhen *neww = makeNode(CaseWhen);
1580  Node *warg;
1581 
1582  warg = (Node *) w->expr;
1583  if (placeholder)
1584  {
1585  /* shorthand form was specified, so expand... */
1586  warg = (Node *) makeSimpleA_Expr(AEXPR_OP, "=",
1587  (Node *) placeholder,
1588  warg,
1589  w->location);
1590  }
1591  neww->expr = (Expr *) transformExprRecurse(pstate, warg);
1592 
1593  neww->expr = (Expr *) coerce_to_boolean(pstate,
1594  (Node *) neww->expr,
1595  "CASE/WHEN");
1596 
1597  warg = (Node *) w->result;
1598  neww->result = (Expr *) transformExprRecurse(pstate, warg);
1599  neww->location = w->location;
1600 
1601  newargs = lappend(newargs, neww);
1602  resultexprs = lappend(resultexprs, neww->result);
1603  }
1604 
1605  newc->args = newargs;
1606 
1607  /* transform the default clause */
1608  defresult = (Node *) c->defresult;
1609  if (defresult == NULL)
1610  {
1611  A_Const *n = makeNode(A_Const);
1612 
1613  n->isnull = true;
1614  n->location = -1;
1615  defresult = (Node *) n;
1616  }
1617  newc->defresult = (Expr *) transformExprRecurse(pstate, defresult);
1618 
1619  /*
1620  * Note: default result is considered the most significant type in
1621  * determining preferred type. This is how the code worked before, but it
1622  * seems a little bogus to me --- tgl
1623  */
1624  resultexprs = lcons(newc->defresult, resultexprs);
1625 
1626  ptype = select_common_type(pstate, resultexprs, "CASE", NULL);
1627  Assert(OidIsValid(ptype));
1628  newc->casetype = ptype;
1629  /* casecollid will be set by parse_collate.c */
1630 
1631  /* Convert default result clause, if necessary */
1632  newc->defresult = (Expr *)
1633  coerce_to_common_type(pstate,
1634  (Node *) newc->defresult,
1635  ptype,
1636  "CASE/ELSE");
1637 
1638  /* Convert when-clause results, if necessary */
1639  foreach(l, newc->args)
1640  {
1641  CaseWhen *w = (CaseWhen *) lfirst(l);
1642 
1643  w->result = (Expr *)
1644  coerce_to_common_type(pstate,
1645  (Node *) w->result,
1646  ptype,
1647  "CASE/WHEN");
1648  }
1649 
1650  /* if any subexpression contained a SRF, complain */
1651  if (pstate->p_last_srf != last_srf)
1652  ereport(ERROR,
1653  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1654  /* translator: %s is name of a SQL construct, eg GROUP BY */
1655  errmsg("set-returning functions are not allowed in %s",
1656  "CASE"),
1657  errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
1658  parser_errposition(pstate,
1659  exprLocation(pstate->p_last_srf))));
1660 
1661  newc->location = c->location;
1662 
1663  return (Node *) newc;
1664 }
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
List * lcons(void *datum, List *list)
Definition: list.c:494
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:266
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:764
void assign_expr_collations(ParseState *pstate, Node *expr)
#define lfirst_node(type, lc)
Definition: pg_list.h:174
char * c
int location
Definition: parsenodes.h:327
Expr * arg
Definition: primnodes.h:1119
int location
Definition: primnodes.h:1122
Oid casetype
Definition: primnodes.h:1117
Expr * defresult
Definition: primnodes.h:1121
List * args
Definition: primnodes.h:1120
int32 typeMod
Definition: primnodes.h:1160
Expr * result
Definition: primnodes.h:1132
Expr * expr
Definition: primnodes.h:1131
int location
Definition: primnodes.h:1133

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(), if(), A_Const::isnull, 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(), transformExprRecurse(), CaseTestExpr::typeId, and CaseTestExpr::typeMod.

Referenced by transformExprRecurse().

◆ transformCoalesceExpr()

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

Definition at line 2100 of file parse_expr.c.

2101 {
2103  Node *last_srf = pstate->p_last_srf;
2104  List *newargs = NIL;
2105  List *newcoercedargs = NIL;
2106  ListCell *args;
2107 
2108  foreach(args, c->args)
2109  {
2110  Node *e = (Node *) lfirst(args);
2111  Node *newe;
2112 
2113  newe = transformExprRecurse(pstate, e);
2114  newargs = lappend(newargs, newe);
2115  }
2116 
2117  newc->coalescetype = select_common_type(pstate, newargs, "COALESCE", NULL);
2118  /* coalescecollid will be set by parse_collate.c */
2119 
2120  /* Convert arguments if necessary */
2121  foreach(args, newargs)
2122  {
2123  Node *e = (Node *) lfirst(args);
2124  Node *newe;
2125 
2126  newe = coerce_to_common_type(pstate, e,
2127  newc->coalescetype,
2128  "COALESCE");
2129  newcoercedargs = lappend(newcoercedargs, newe);
2130  }
2131 
2132  /* if any subexpression contained a SRF, complain */
2133  if (pstate->p_last_srf != last_srf)
2134  ereport(ERROR,
2135  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2136  /* translator: %s is name of a SQL construct, eg GROUP BY */
2137  errmsg("set-returning functions are not allowed in %s",
2138  "COALESCE"),
2139  errhint("You might be able to move the set-returning function into a LATERAL FROM item."),
2140  parser_errposition(pstate,
2141  exprLocation(pstate->p_last_srf))));
2142 
2143  newc->args = newcoercedargs;
2144  newc->location = c->location;
2145  return (Node *) newc;
2146 }
List * args
Definition: primnodes.h:1271
Oid coalescetype
Definition: primnodes.h:1269

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().

◆ transformCollateClause()

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

Definition at line 2603 of file parse_expr.c.

2604 {
2605  CollateExpr *newc;
2606  Oid argtype;
2607 
2608  newc = makeNode(CollateExpr);
2609  newc->arg = (Expr *) transformExprRecurse(pstate, c->arg);
2610 
2611  argtype = exprType((Node *) newc->arg);
2612 
2613  /*
2614  * The unknown type is not collatable, but coerce_type() takes care of it
2615  * separately, so we'll let it go here.
2616  */
2617  if (!type_is_collatable(argtype) && argtype != UNKNOWNOID)
2618  ereport(ERROR,
2619  (errcode(ERRCODE_DATATYPE_MISMATCH),
2620  errmsg("collations are not supported by type %s",
2621  format_type_be(argtype)),
2622  parser_errposition(pstate, c->location)));
2623 
2624  newc->collOid = LookupCollation(pstate, c->collname, c->location);
2625  newc->location = c->location;
2626 
2627  return (Node *) newc;
2628 }
bool type_is_collatable(Oid typid)
Definition: lsyscache.c:3039
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
Definition: parse_type.c:515
Expr * arg
Definition: primnodes.h:1087

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

Referenced by transformExprRecurse().

◆ transformColumnRef()

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

Definition at line 432 of file parse_expr.c.

433 {
434  Node *node = NULL;
435  char *nspname = NULL;
436  char *relname = NULL;
437  char *colname = NULL;
438  ParseNamespaceItem *nsitem;
439  int levels_up;
440  enum
441  {
442  CRERR_NO_COLUMN,
443  CRERR_NO_RTE,
444  CRERR_WRONG_DB,
445  CRERR_TOO_MANY
446  } crerr = CRERR_NO_COLUMN;
447  const char *err;
448 
449  /*
450  * Check to see if the column reference is in an invalid place within the
451  * query. We allow column references in most places, except in default
452  * expressions and partition bound expressions.
453  */
454  err = NULL;
455  switch (pstate->p_expr_kind)
456  {
457  case EXPR_KIND_NONE:
458  Assert(false); /* can't happen */
459  break;
460  case EXPR_KIND_OTHER:
461  case EXPR_KIND_JOIN_ON:
465  case EXPR_KIND_WHERE:
466  case EXPR_KIND_POLICY:
467  case EXPR_KIND_HAVING:
468  case EXPR_KIND_FILTER:
479  case EXPR_KIND_GROUP_BY:
480  case EXPR_KIND_ORDER_BY:
482  case EXPR_KIND_LIMIT:
483  case EXPR_KIND_OFFSET:
484  case EXPR_KIND_RETURNING:
485  case EXPR_KIND_VALUES:
501  /* okay */
502  break;
503 
505  err = _("cannot use column reference in DEFAULT expression");
506  break;
508  err = _("cannot use column reference in partition bound expression");
509  break;
510 
511  /*
512  * There is intentionally no default: case here, so that the
513  * compiler will warn if we add a new ParseExprKind without
514  * extending this switch. If we do see an unrecognized value at
515  * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
516  * which is sane anyway.
517  */
518  }
519  if (err)
520  ereport(ERROR,
521  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
522  errmsg_internal("%s", err),
523  parser_errposition(pstate, cref->location)));
524 
525  /*
526  * Give the PreParseColumnRefHook, if any, first shot. If it returns
527  * non-null then that's all, folks.
528  */
529  if (pstate->p_pre_columnref_hook != NULL)
530  {
531  node = pstate->p_pre_columnref_hook(pstate, cref);
532  if (node != NULL)
533  return node;
534  }
535 
536  /*----------
537  * The allowed syntaxes are:
538  *
539  * A First try to resolve as unqualified column name;
540  * if no luck, try to resolve as unqualified table name (A.*).
541  * A.B A is an unqualified table name; B is either a
542  * column or function name (trying column name first).
543  * A.B.C schema A, table B, col or func name C.
544  * A.B.C.D catalog A, schema B, table C, col or func D.
545  * A.* A is an unqualified table name; means whole-row value.
546  * A.B.* whole-row value of table B in schema A.
547  * A.B.C.* whole-row value of table C in schema B in catalog A.
548  *
549  * We do not need to cope with bare "*"; that will only be accepted by
550  * the grammar at the top level of a SELECT list, and transformTargetList
551  * will take care of it before it ever gets here. Also, "A.*" etc will
552  * be expanded by transformTargetList if they appear at SELECT top level,
553  * so here we are only going to see them as function or operator inputs.
554  *
555  * Currently, if a catalog name is given then it must equal the current
556  * database name; we check it here and then discard it.
557  *----------
558  */
559  switch (list_length(cref->fields))
560  {
561  case 1:
562  {
563  Node *field1 = (Node *) linitial(cref->fields);
564 
565  colname = strVal(field1);
566 
567  /* Try to identify as an unqualified column */
568  node = colNameToVar(pstate, colname, false, cref->location);
569 
570  if (node == NULL)
571  {
572  /*
573  * Not known as a column of any range-table entry.
574  *
575  * Try to find the name as a relation. Note that only
576  * relations already entered into the rangetable will be
577  * recognized.
578  *
579  * This is a hack for backwards compatibility with
580  * PostQUEL-inspired syntax. The preferred form now is
581  * "rel.*".
582  */
583  nsitem = refnameNamespaceItem(pstate, NULL, colname,
584  cref->location,
585  &levels_up);
586  if (nsitem)
587  node = transformWholeRowRef(pstate, nsitem, levels_up,
588  cref->location);
589  }
590  break;
591  }
592  case 2:
593  {
594  Node *field1 = (Node *) linitial(cref->fields);
595  Node *field2 = (Node *) lsecond(cref->fields);
596 
597  relname = strVal(field1);
598 
599  /* Locate the referenced nsitem */
600  nsitem = refnameNamespaceItem(pstate, nspname, relname,
601  cref->location,
602  &levels_up);
603  if (nsitem == NULL)
604  {
605  crerr = CRERR_NO_RTE;
606  break;
607  }
608 
609  /* Whole-row reference? */
610  if (IsA(field2, A_Star))
611  {
612  node = transformWholeRowRef(pstate, nsitem, levels_up,
613  cref->location);
614  break;
615  }
616 
617  colname = strVal(field2);
618 
619  /* Try to identify as a column of the nsitem */
620  node = scanNSItemForColumn(pstate, nsitem, levels_up, colname,
621  cref->location);
622  if (node == NULL)
623  {
624  /* Try it as a function call on the whole row */
625  node = transformWholeRowRef(pstate, nsitem, levels_up,
626  cref->location);
627  node = ParseFuncOrColumn(pstate,
628  list_make1(makeString(colname)),
629  list_make1(node),
630  pstate->p_last_srf,
631  NULL,
632  false,
633  cref->location);
634  }
635  break;
636  }
637  case 3:
638  {
639  Node *field1 = (Node *) linitial(cref->fields);
640  Node *field2 = (Node *) lsecond(cref->fields);
641  Node *field3 = (Node *) lthird(cref->fields);
642 
643  nspname = strVal(field1);
644  relname = strVal(field2);
645 
646  /* Locate the referenced nsitem */
647  nsitem = refnameNamespaceItem(pstate, nspname, relname,
648  cref->location,
649  &levels_up);
650  if (nsitem == NULL)
651  {
652  crerr = CRERR_NO_RTE;
653  break;
654  }
655 
656  /* Whole-row reference? */
657  if (IsA(field3, A_Star))
658  {
659  node = transformWholeRowRef(pstate, nsitem, levels_up,
660  cref->location);
661  break;
662  }
663 
664  colname = strVal(field3);
665 
666  /* Try to identify as a column of the nsitem */
667  node = scanNSItemForColumn(pstate, nsitem, levels_up, colname,
668  cref->location);
669  if (node == NULL)
670  {
671  /* Try it as a function call on the whole row */
672  node = transformWholeRowRef(pstate, nsitem, levels_up,
673  cref->location);
674  node = ParseFuncOrColumn(pstate,
675  list_make1(makeString(colname)),
676  list_make1(node),
677  pstate->p_last_srf,
678  NULL,
679  false,
680  cref->location);
681  }
682  break;
683  }
684  case 4:
685  {
686  Node *field1 = (Node *) linitial(cref->fields);
687  Node *field2 = (Node *) lsecond(cref->fields);
688  Node *field3 = (Node *) lthird(cref->fields);
689  Node *field4 = (Node *) lfourth(cref->fields);
690  char *catname;
691 
692  catname = strVal(field1);
693  nspname = strVal(field2);
694  relname = strVal(field3);
695 
696  /*
697  * We check the catalog name and then ignore it.
698  */
699  if (strcmp(catname, get_database_name(MyDatabaseId)) != 0)
700  {
701  crerr = CRERR_WRONG_DB;
702  break;
703  }
704 
705  /* Locate the referenced nsitem */
706  nsitem = refnameNamespaceItem(pstate, nspname, relname,
707  cref->location,
708  &levels_up);
709  if (nsitem == NULL)
710  {
711  crerr = CRERR_NO_RTE;
712  break;
713  }
714 
715  /* Whole-row reference? */
716  if (IsA(field4, A_Star))
717  {
718  node = transformWholeRowRef(pstate, nsitem, levels_up,
719  cref->location);
720  break;
721  }
722 
723  colname = strVal(field4);
724 
725  /* Try to identify as a column of the nsitem */
726  node = scanNSItemForColumn(pstate, nsitem, levels_up, colname,
727  cref->location);
728  if (node == NULL)
729  {
730  /* Try it as a function call on the whole row */
731  node = transformWholeRowRef(pstate, nsitem, levels_up,
732  cref->location);
733  node = ParseFuncOrColumn(pstate,
734  list_make1(makeString(colname)),
735  list_make1(node),
736  pstate->p_last_srf,
737  NULL,
738  false,
739  cref->location);
740  }
741  break;
742  }
743  default:
744  crerr = CRERR_TOO_MANY; /* too many dotted names */
745  break;
746  }
747 
748  /*
749  * Now give the PostParseColumnRefHook, if any, a chance. We pass the
750  * translation-so-far so that it can throw an error if it wishes in the
751  * case that it has a conflicting interpretation of the ColumnRef. (If it
752  * just translates anyway, we'll throw an error, because we can't undo
753  * whatever effects the preceding steps may have had on the pstate.) If it
754  * returns NULL, use the standard translation, or throw a suitable error
755  * if there is none.
756  */
757  if (pstate->p_post_columnref_hook != NULL)
758  {
759  Node *hookresult;
760 
761  hookresult = pstate->p_post_columnref_hook(pstate, cref, node);
762  if (node == NULL)
763  node = hookresult;
764  else if (hookresult != NULL)
765  ereport(ERROR,
766  (errcode(ERRCODE_AMBIGUOUS_COLUMN),
767  errmsg("column reference \"%s\" is ambiguous",
768  NameListToString(cref->fields)),
769  parser_errposition(pstate, cref->location)));
770  }
771 
772  /*
773  * Throw error if no translation found.
774  */
775  if (node == NULL)
776  {
777  switch (crerr)
778  {
779  case CRERR_NO_COLUMN:
780  errorMissingColumn(pstate, relname, colname, cref->location);
781  break;
782  case CRERR_NO_RTE:
783  errorMissingRTE(pstate, makeRangeVar(nspname, relname,
784  cref->location));
785  break;
786  case CRERR_WRONG_DB:
787  ereport(ERROR,
788  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
789  errmsg("cross-database references are not implemented: %s",
790  NameListToString(cref->fields)),
791  parser_errposition(pstate, cref->location)));
792  break;
793  case CRERR_TOO_MANY:
794  ereport(ERROR,
795  (errcode(ERRCODE_SYNTAX_ERROR),
796  errmsg("improper qualified name (too many dotted names): %s",
797  NameListToString(cref->fields)),
798  parser_errposition(pstate, cref->location)));
799  break;
800  }
801  }
802 
803  return node;
804 }
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2981
int errmsg_internal(const char *fmt,...)
Definition: elog.c:993
#define _(x)
Definition: elog.c:90
Oid MyDatabaseId
Definition: globals.c:89
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
Definition: makefuncs.c:422
char * NameListToString(List *names)
Definition: namespace.c:3145
static Node * transformWholeRowRef(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location)
Definition: parse_expr.c:2452
Node * ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
Definition: parse_func.c:90
void errorMissingColumn(ParseState *pstate, const char *relname, const char *colname, int location)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
Node * scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, const char *colname, int location)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
Node * colNameToVar(ParseState *pstate, const char *colname, bool localonly, int location)
NameData relname
Definition: pg_class.h:38
#define lthird(l)
Definition: pg_list.h:186
#define lfourth(l)
Definition: pg_list.h:191
int location
Definition: parsenodes.h:258
List * fields
Definition: parsenodes.h:257
ParseExprKind p_expr_kind
Definition: parse_node.h:197
PreParseColumnRefHook p_pre_columnref_hook
Definition: parse_node.h:221
PostParseColumnRefHook p_post_columnref_hook
Definition: parse_node.h:222
String * makeString(char *str)
Definition: value.c:63

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_CYCLE_MARK, 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_MERGE_WHEN, 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_STATS_EXPRESSION, 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(), refnameNamespaceItem(), relname, scanNSItemForColumn(), strVal, and transformWholeRowRef().

Referenced by transformExprRecurse().

◆ transformCurrentOfExpr()

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

Definition at line 2400 of file parse_expr.c.

2401 {
2402  /* CURRENT OF can only appear at top level of UPDATE/DELETE */
2403  Assert(pstate->p_target_nsitem != NULL);
2404  cexpr->cvarno = pstate->p_target_nsitem->p_rtindex;
2405 
2406  /*
2407  * Check to see if the cursor name matches a parameter of type REFCURSOR.
2408  * If so, replace the raw name reference with a parameter reference. (This
2409  * is a hack for the convenience of plpgsql.)
2410  */
2411  if (cexpr->cursor_name != NULL) /* in case already transformed */
2412  {
2413  ColumnRef *cref = makeNode(ColumnRef);
2414  Node *node = NULL;
2415 
2416  /* Build an unqualified ColumnRef with the given name */
2417  cref->fields = list_make1(makeString(cexpr->cursor_name));
2418  cref->location = -1;
2419 
2420  /* See if there is a translation available from a parser hook */
2421  if (pstate->p_pre_columnref_hook != NULL)
2422  node = pstate->p_pre_columnref_hook(pstate, cref);
2423  if (node == NULL && pstate->p_post_columnref_hook != NULL)
2424  node = pstate->p_post_columnref_hook(pstate, cref, NULL);
2425 
2426  /*
2427  * XXX Should we throw an error if we get a translation that isn't a
2428  * refcursor Param? For now it seems best to silently ignore false
2429  * matches.
2430  */
2431  if (node != NULL && IsA(node, Param))
2432  {
2433  Param *p = (Param *) node;
2434 
2435  if (p->paramkind == PARAM_EXTERN &&
2436  p->paramtype == REFCURSOROID)
2437  {
2438  /* Matches, so convert CURRENT OF to a param reference */
2439  cexpr->cursor_name = NULL;
2440  cexpr->cursor_param = p->paramid;
2441  }
2442  }
2443  }
2444 
2445  return (Node *) cexpr;
2446 }
@ PARAM_EXTERN
Definition: primnodes.h:302
char * cursor_name
Definition: primnodes.h:1464
int paramid
Definition: primnodes.h:312
Oid paramtype
Definition: primnodes.h:313
ParamKind paramkind
Definition: primnodes.h:311
ParseNamespaceItem * p_target_nsitem
Definition: parse_node.h:194

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, ParseNamespaceItem::p_rtindex, ParseState::p_target_nsitem, PARAM_EXTERN, Param::paramid, Param::paramkind, and Param::paramtype.

Referenced by transformExprRecurse().

◆ transformExpr()

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

◆ transformExprRecurse()

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

Definition at line 110 of file parse_expr.c.

111 {
112  Node *result;
113 
114  if (expr == NULL)
115  return NULL;
116 
117  /* Guard against stack overflow due to overly complex expressions */
119 
120  switch (nodeTag(expr))
121  {
122  case T_ColumnRef:
123  result = transformColumnRef(pstate, (ColumnRef *) expr);
124  break;
125 
126  case T_ParamRef:
127  result = transformParamRef(pstate, (ParamRef *) expr);
128  break;
129 
130  case T_A_Const:
131  result = (Node *) make_const(pstate, (A_Const *) expr);
132  break;
133 
134  case T_A_Indirection:
135  result = transformIndirection(pstate, (A_Indirection *) expr);
136  break;
137 
138  case T_A_ArrayExpr:
139  result = transformArrayExpr(pstate, (A_ArrayExpr *) expr,
140  InvalidOid, InvalidOid, -1);
141  break;
142 
143  case T_TypeCast:
144  result = transformTypeCast(pstate, (TypeCast *) expr);
145  break;
146 
147  case T_CollateClause:
148  result = transformCollateClause(pstate, (CollateClause *) expr);
149  break;
150 
151  case T_A_Expr:
152  {
153  A_Expr *a = (A_Expr *) expr;
154 
155  switch (a->kind)
156  {
157  case AEXPR_OP:
158  result = transformAExprOp(pstate, a);
159  break;
160  case AEXPR_OP_ANY:
161  result = transformAExprOpAny(pstate, a);
162  break;
163  case AEXPR_OP_ALL:
164  result = transformAExprOpAll(pstate, a);
165  break;
166  case AEXPR_DISTINCT:
167  case AEXPR_NOT_DISTINCT:
168  result = transformAExprDistinct(pstate, a);
169  break;
170  case AEXPR_NULLIF:
171  result = transformAExprNullIf(pstate, a);
172  break;
173  case AEXPR_IN:
174  result = transformAExprIn(pstate, a);
175  break;
176  case AEXPR_LIKE:
177  case AEXPR_ILIKE:
178  case AEXPR_SIMILAR:
179  /* we can transform these just like AEXPR_OP */
180  result = transformAExprOp(pstate, a);
181  break;
182  case AEXPR_BETWEEN:
183  case AEXPR_NOT_BETWEEN:
184  case AEXPR_BETWEEN_SYM:
186  result = transformAExprBetween(pstate, a);
187  break;
188  default:
189  elog(ERROR, "unrecognized A_Expr kind: %d", a->kind);
190  result = NULL; /* keep compiler quiet */
191  break;
192  }
193  break;
194  }
195 
196  case T_BoolExpr:
197  result = transformBoolExpr(pstate, (BoolExpr *) expr);
198  break;
199 
200  case T_FuncCall:
201  result = transformFuncCall(pstate, (FuncCall *) expr);
202  break;
203 
204  case T_MultiAssignRef:
205  result = transformMultiAssignRef(pstate, (MultiAssignRef *) expr);
206  break;
207 
208  case T_GroupingFunc:
209  result = transformGroupingFunc(pstate, (GroupingFunc *) expr);
210  break;
211 
212  case T_NamedArgExpr:
213  {
214  NamedArgExpr *na = (NamedArgExpr *) expr;
215 
216  na->arg = (Expr *) transformExprRecurse(pstate, (Node *) na->arg);
217  result = expr;
218  break;
219  }
220 
221  case T_SubLink:
222  result = transformSubLink(pstate, (SubLink *) expr);
223  break;
224 
225  case T_CaseExpr:
226  result = transformCaseExpr(pstate, (CaseExpr *) expr);
227  break;
228 
229  case T_RowExpr:
230  result = transformRowExpr(pstate, (RowExpr *) expr, false);
231  break;
232 
233  case T_CoalesceExpr:
234  result = transformCoalesceExpr(pstate, (CoalesceExpr *) expr);
235  break;
236 
237  case T_MinMaxExpr:
238  result = transformMinMaxExpr(pstate, (MinMaxExpr *) expr);
239  break;
240 
241  case T_XmlExpr:
242  result = transformXmlExpr(pstate, (XmlExpr *) expr);
243  break;
244 
245  case T_XmlSerialize:
246  result = transformXmlSerialize(pstate, (XmlSerialize *) expr);
247  break;
248 
249  case T_NullTest:
250  {
251  NullTest *n = (NullTest *) expr;
252 
253  n->arg = (Expr *) transformExprRecurse(pstate, (Node *) n->arg);
254  /* the argument can be any type, so don't coerce it */
255  n->argisrow = type_is_rowtype(exprType((Node *) n->arg));
256  result = expr;
257  break;
258  }
259 
260  case T_BooleanTest:
261  result = transformBooleanTest(pstate, (BooleanTest *) expr);
262  break;
263 
264  case T_CurrentOfExpr:
265  result = transformCurrentOfExpr(pstate, (CurrentOfExpr *) expr);
266  break;
267 
268  /*
269  * In all places where DEFAULT is legal, the caller should have
270  * processed it rather than passing it to transformExpr().
271  */
272  case T_SetToDefault:
273  ereport(ERROR,
274  (errcode(ERRCODE_SYNTAX_ERROR),
275  errmsg("DEFAULT is not allowed in this context"),
276  parser_errposition(pstate,
277  ((SetToDefault *) expr)->location)));
278  break;
279 
280  /*
281  * CaseTestExpr doesn't require any processing; it is only
282  * injected into parse trees in a fully-formed state.
283  *
284  * Ordinarily we should not see a Var here, but it is convenient
285  * for transformJoinUsingClause() to create untransformed operator
286  * trees containing already-transformed Vars. The best
287  * alternative would be to deconstruct and reconstruct column
288  * references, which seems expensively pointless. So allow it.
289  */
290  case T_CaseTestExpr:
291  case T_Var:
292  {
293  result = (Node *) expr;
294  break;
295  }
296 
297  default:
298  /* should not reach here */
299  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
300  result = NULL; /* keep compiler quiet */
301  break;
302  }
303 
304  return result;
305 }
bool type_is_rowtype(Oid typid)
Definition: lsyscache.c:2613
#define nodeTag(nodeptr)
Definition: nodes.h:116
Node * transformGroupingFunc(ParseState *pstate, GroupingFunc *p)
Definition: parse_agg.c:247
static Node * transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr)
Definition: parse_expr.c:2400
static Node * transformAExprOpAll(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:939
static Node * transformAExprIn(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1046
static Node * transformAExprOpAny(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:925
static Node * transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
Definition: parse_expr.c:2317
static Node * transformAExprNullIf(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1004
static Node * transformColumnRef(ParseState *pstate, ColumnRef *cref)
Definition: parse_expr.c:432
static Node * transformCollateClause(ParseState *pstate, CollateClause *c)
Definition: parse_expr.c:2603
static Node * transformBoolExpr(ParseState *pstate, BoolExpr *a)
Definition: parse_expr.c:1298
static Node * transformFuncCall(ParseState *pstate, FuncCall *fn)
Definition: parse_expr.c:1334
static Node * transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
Definition: parse_expr.c:2149
static Node * transformCoalesceExpr(ParseState *pstate, CoalesceExpr *c)
Definition: parse_expr.c:2100
static Node * transformSubLink(ParseState *pstate, SubLink *sublink)
Definition: parse_expr.c:1667
static Node * transformAExprOp(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:844
static Node * transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref)
Definition: parse_expr.c:1379
static Node * transformBooleanTest(ParseState *pstate, BooleanTest *b)
Definition: parse_expr.c:2360
static Node * transformTypeCast(ParseState *pstate, TypeCast *tc)
Definition: parse_expr.c:2519
static Node * transformParamRef(ParseState *pstate, ParamRef *pref)
Definition: parse_expr.c:807
static Node * transformCaseExpr(ParseState *pstate, CaseExpr *c)
Definition: parse_expr.c:1527
static Node * transformIndirection(ParseState *pstate, A_Indirection *ind)
Definition: parse_expr.c:360
static Node * transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
Definition: parse_expr.c:2062
static Node * transformXmlExpr(ParseState *pstate, XmlExpr *x)
Definition: parse_expr.c:2188
static Node * transformAExprBetween(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:1204
static Node * transformAExprDistinct(ParseState *pstate, A_Expr *a)
Definition: parse_expr.c:953
Const * make_const(ParseState *pstate, A_Const *aconst)
Definition: parse_node.c:351
@ AEXPR_NULLIF
Definition: parsenodes.h:281
@ AEXPR_ILIKE
Definition: parsenodes.h:284
@ AEXPR_IN
Definition: parsenodes.h:282
@ AEXPR_DISTINCT
Definition: parsenodes.h:279
@ AEXPR_SIMILAR
Definition: parsenodes.h:285
@ AEXPR_LIKE
Definition: parsenodes.h:283
@ AEXPR_OP_ANY
Definition: parsenodes.h:277
@ AEXPR_OP_ALL
Definition: parsenodes.h:278
void check_stack_depth(void)
Definition: postgres.c:3440
Expr * arg
Definition: primnodes.h:627

References a, 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_OP, AEXPR_OP_ALL, AEXPR_OP_ANY, AEXPR_SIMILAR, NamedArgExpr::arg, NullTest::arg, NullTest::argisrow, check_stack_depth(), elog(), ereport, errcode(), errmsg(), ERROR, exprType(), InvalidOid, make_const(), nodeTag, parser_errposition(), transformAExprBetween(), transformAExprDistinct(), transformAExprIn(), transformAExprNullIf(), transformAExprOp(), transformAExprOpAll(), transformAExprOpAny(), transformArrayExpr(), transformBooleanTest(), transformBoolExpr(), transformCaseExpr(), transformCoalesceExpr(), transformCollateClause(), transformColumnRef(), transformCurrentOfExpr(), transformFuncCall(), transformGroupingFunc(), transformIndirection(), transformMinMaxExpr(), transformMultiAssignRef(), transformParamRef(), transformRowExpr(), transformSubLink(), transformTypeCast(), transformXmlExpr(), transformXmlSerialize(), and type_is_rowtype().

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

◆ transformFuncCall()

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

Definition at line 1334 of file parse_expr.c.

1335 {
1336  Node *last_srf = pstate->p_last_srf;
1337  List *targs;
1338  ListCell *args;
1339 
1340  /* Transform the list of arguments ... */
1341  targs = NIL;
1342  foreach(args, fn->args)
1343  {
1344  targs = lappend(targs, transformExprRecurse(pstate,
1345  (Node *) lfirst(args)));
1346  }
1347 
1348  /*
1349  * When WITHIN GROUP is used, we treat its ORDER BY expressions as
1350  * additional arguments to the function, for purposes of function lookup
1351  * and argument type coercion. So, transform each such expression and add
1352  * them to the targs list. We don't explicitly mark where each argument
1353  * came from, but ParseFuncOrColumn can tell what's what by reference to
1354  * list_length(fn->agg_order).
1355  */
1356  if (fn->agg_within_group)
1357  {
1358  Assert(fn->agg_order != NIL);
1359  foreach(args, fn->agg_order)
1360  {
1361  SortBy *arg = (SortBy *) lfirst(args);
1362 
1363  targs = lappend(targs, transformExpr(pstate, arg->node,
1365  }
1366  }
1367 
1368  /* ... and hand off to ParseFuncOrColumn */
1369  return ParseFuncOrColumn(pstate,
1370  fn->funcname,
1371  targs,
1372  last_srf,
1373  fn,
1374  false,
1375  fn->location);
1376 }
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition: parse_expr.c:92
static void * fn(void *arg)

References arg, generate_unaccent_rules::args, Assert(), EXPR_KIND_ORDER_BY, fn(), lappend(), lfirst, NIL, ParseState::p_last_srf, ParseFuncOrColumn(), transformExpr(), and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformIndirection()

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

Definition at line 360 of file parse_expr.c.

361 {
362  Node *last_srf = pstate->p_last_srf;
363  Node *result = transformExprRecurse(pstate, ind->arg);
364  List *subscripts = NIL;
365  int location = exprLocation(result);
366  ListCell *i;
367 
368  /*
369  * We have to split any field-selection operations apart from
370  * subscripting. Adjacent A_Indices nodes have to be treated as a single
371  * multidimensional subscript operation.
372  */
373  foreach(i, ind->indirection)
374  {
375  Node *n = lfirst(i);
376 
377  if (IsA(n, A_Indices))
378  subscripts = lappend(subscripts, n);
379  else if (IsA(n, A_Star))
380  {
381  ereport(ERROR,
382  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
383  errmsg("row expansion via \"*\" is not supported here"),
384  parser_errposition(pstate, location)));
385  }
386  else
387  {
388  Node *newresult;
389 
390  Assert(IsA(n, String));
391 
392  /* process subscripts before this field selection */
393  if (subscripts)
394  result = (Node *) transformContainerSubscripts(pstate,
395  result,
396  exprType(result),
397  exprTypmod(result),
398  subscripts,
399  false);
400  subscripts = NIL;
401 
402  newresult = ParseFuncOrColumn(pstate,
403  list_make1(n),
404  list_make1(result),
405  last_srf,
406  NULL,
407  false,
408  location);
409  if (newresult == NULL)
410  unknown_attribute(pstate, result, strVal(n), location);
411  result = newresult;
412  }
413  }
414  /* process trailing subscripts, if any */
415  if (subscripts)
416  result = (Node *) transformContainerSubscripts(pstate,
417  result,
418  exprType(result),
419  exprTypmod(result),
420  subscripts,
421  false);
422 
423  return result;
424 }
static void unknown_attribute(ParseState *pstate, Node *relref, const char *attname, int location)
Definition: parse_expr.c:314
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
Definition: parse_node.c:247
Definition: value.h:64

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

Referenced by transformExprRecurse().

◆ transformMinMaxExpr()

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

Definition at line 2149 of file parse_expr.c.

2150 {
2151  MinMaxExpr *newm = makeNode(MinMaxExpr);
2152  List *newargs = NIL;
2153  List *newcoercedargs = NIL;
2154  const char *funcname = (m->op == IS_GREATEST) ? "GREATEST" : "LEAST";
2155  ListCell *args;
2156 
2157  newm->op = m->op;
2158  foreach(args, m->args)
2159  {
2160  Node *e = (Node *) lfirst(args);
2161  Node *newe;
2162 
2163  newe = transformExprRecurse(pstate, e);
2164  newargs = lappend(newargs, newe);
2165  }
2166 
2167  newm->minmaxtype = select_common_type(pstate, newargs, funcname, NULL);
2168  /* minmaxcollid and inputcollid will be set by parse_collate.c */
2169 
2170  /* Convert arguments if necessary */
2171  foreach(args, newargs)
2172  {
2173  Node *e = (Node *) lfirst(args);
2174  Node *newe;
2175 
2176  newe = coerce_to_common_type(pstate, e,
2177  newm->minmaxtype,
2178  funcname);
2179  newcoercedargs = lappend(newcoercedargs, newe);
2180  }
2181 
2182  newm->args = newcoercedargs;
2183  newm->location = m->location;
2184  return (Node *) newm;
2185 }
@ IS_GREATEST
Definition: primnodes.h:1280
List * args
Definition: primnodes.h:1291
int location
Definition: primnodes.h:1292
MinMaxOp op
Definition: primnodes.h:1290
Oid minmaxtype
Definition: primnodes.h:1287

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().

◆ transformMultiAssignRef()

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

Definition at line 1379 of file parse_expr.c.

1380 {
1381  SubLink *sublink;
1382  RowExpr *rexpr;
1383  Query *qtree;
1384  TargetEntry *tle;
1385 
1386  /* We should only see this in first-stage processing of UPDATE tlists */
1388 
1389  /* We only need to transform the source if this is the first column */
1390  if (maref->colno == 1)
1391  {
1392  /*
1393  * For now, we only allow EXPR SubLinks and RowExprs as the source of
1394  * an UPDATE multiassignment. This is sufficient to cover interesting
1395  * cases; at worst, someone would have to write (SELECT * FROM expr)
1396  * to expand a composite-returning expression of another form.
1397  */
1398  if (IsA(maref->source, SubLink) &&
1399  ((SubLink *) maref->source)->subLinkType == EXPR_SUBLINK)
1400  {
1401  /* Relabel it as a MULTIEXPR_SUBLINK */
1402  sublink = (SubLink *) maref->source;
1403  sublink->subLinkType = MULTIEXPR_SUBLINK;
1404  /* And transform it */
1405  sublink = (SubLink *) transformExprRecurse(pstate,
1406  (Node *) sublink);
1407 
1408  qtree = castNode(Query, sublink->subselect);
1409 
1410  /* Check subquery returns required number of columns */
1411  if (count_nonjunk_tlist_entries(qtree->targetList) != maref->ncolumns)
1412  ereport(ERROR,
1413  (errcode(ERRCODE_SYNTAX_ERROR),
1414  errmsg("number of columns does not match number of values"),
1415  parser_errposition(pstate, sublink->location)));
1416 
1417  /*
1418  * Build a resjunk tlist item containing the MULTIEXPR SubLink,
1419  * and add it to pstate->p_multiassign_exprs, whence it will later
1420  * get appended to the completed targetlist. We needn't worry
1421  * about selecting a resno for it; transformUpdateStmt will do
1422  * that.
1423  */
1424  tle = makeTargetEntry((Expr *) sublink, 0, NULL, true);
1426  tle);
1427 
1428  /*
1429  * Assign a unique-within-this-targetlist ID to the MULTIEXPR
1430  * SubLink. We can just use its position in the
1431  * p_multiassign_exprs list.
1432  */
1433  sublink->subLinkId = list_length(pstate->p_multiassign_exprs);
1434  }
1435  else if (IsA(maref->source, RowExpr))
1436  {
1437  /* Transform the RowExpr, allowing SetToDefault items */
1438  rexpr = (RowExpr *) transformRowExpr(pstate,
1439  (RowExpr *) maref->source,
1440  true);
1441 
1442  /* Check it returns required number of columns */
1443  if (list_length(rexpr->args) != maref->ncolumns)
1444  ereport(ERROR,
1445  (errcode(ERRCODE_SYNTAX_ERROR),
1446  errmsg("number of columns does not match number of values"),
1447  parser_errposition(pstate, rexpr->location)));
1448 
1449  /*
1450  * Temporarily append it to p_multiassign_exprs, so we can get it
1451  * back when we come back here for additional columns.
1452  */
1453  tle = makeTargetEntry((Expr *) rexpr, 0, NULL, true);
1455  tle);
1456  }
1457  else
1458  ereport(ERROR,
1459  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1460  errmsg("source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"),
1461  parser_errposition(pstate, exprLocation(maref->source))));
1462  }
1463  else
1464  {
1465  /*
1466  * Second or later column in a multiassignment. Re-fetch the
1467  * transformed SubLink or RowExpr, which we assume is still the last
1468  * entry in p_multiassign_exprs.
1469  */
1470  Assert(pstate->p_multiassign_exprs != NIL);
1471  tle = (TargetEntry *) llast(pstate->p_multiassign_exprs);
1472  }
1473 
1474  /*
1475  * Emit the appropriate output expression for the current column
1476  */
1477  if (IsA(tle->expr, SubLink))
1478  {
1479  Param *param;
1480 
1481  sublink = (SubLink *) tle->expr;
1482  Assert(sublink->subLinkType == MULTIEXPR_SUBLINK);
1483  qtree = castNode(Query, sublink->subselect);
1484 
1485  /* Build a Param representing the current subquery output column */
1486  tle = (TargetEntry *) list_nth(qtree->targetList, maref->colno - 1);
1487  Assert(!tle->resjunk);
1488 
1489  param = makeNode(Param);
1490  param->paramkind = PARAM_MULTIEXPR;
1491  param->paramid = (sublink->subLinkId << 16) | maref->colno;
1492  param->paramtype = exprType((Node *) tle->expr);
1493  param->paramtypmod = exprTypmod((Node *) tle->expr);
1494  param->paramcollid = exprCollation((Node *) tle->expr);
1495  param->location = exprLocation((Node *) tle->expr);
1496 
1497  return (Node *) param;
1498  }
1499 
1500  if (IsA(tle->expr, RowExpr))
1501  {
1502  Node *result;
1503 
1504  rexpr = (RowExpr *) tle->expr;
1505 
1506  /* Just extract and return the next element of the RowExpr */
1507  result = (Node *) list_nth(rexpr->args, maref->colno - 1);
1508 
1509  /*
1510  * If we're at the last column, delete the RowExpr from
1511  * p_multiassign_exprs; we don't need it anymore, and don't want it in
1512  * the finished UPDATE tlist. We assume this is still the last entry
1513  * in p_multiassign_exprs.
1514  */
1515  if (maref->colno == maref->ncolumns)
1516  pstate->p_multiassign_exprs =
1518 
1519  return result;
1520  }
1521 
1522  elog(ERROR, "unexpected expr type in multiassign list");
1523  return NULL; /* keep compiler quiet */
1524 }
List * list_delete_last(List *list)
Definition: list.c:956
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:238
static void * list_nth(const List *list, int n)
Definition: pg_list.h:297
@ MULTIEXPR_SUBLINK
Definition: primnodes.h:829
@ PARAM_MULTIEXPR
Definition: primnodes.h:305
int32 paramtypmod
Definition: primnodes.h:314
int location
Definition: primnodes.h:316
Oid paramcollid
Definition: primnodes.h:315
List * p_multiassign_exprs
Definition: parse_node.h:199
List * targetList
Definition: parsenodes.h:160
int location
Definition: primnodes.h:1224
Expr * expr
Definition: primnodes.h:1555
bool resjunk
Definition: primnodes.h:1562
int count_nonjunk_tlist_entries(List *tlist)
Definition: tlist.c:186

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_last(), 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().

◆ transformParamRef()

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

Definition at line 807 of file parse_expr.c.

808 {
809  Node *result;
810 
811  /*
812  * The core parser knows nothing about Params. If a hook is supplied,
813  * call it. If not, or if the hook returns NULL, throw a generic error.
814  */
815  if (pstate->p_paramref_hook != NULL)
816  result = pstate->p_paramref_hook(pstate, pref);
817  else
818  result = NULL;
819 
820  if (result == NULL)
821  ereport(ERROR,
822  (errcode(ERRCODE_UNDEFINED_PARAMETER),
823  errmsg("there is no parameter $%d", pref->number),
824  parser_errposition(pstate, pref->location)));
825 
826  return result;
827 }
int location
Definition: parsenodes.h:268
int number
Definition: parsenodes.h:267
ParseParamRefHook p_paramref_hook
Definition: parse_node.h:223

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

Referenced by transformExprRecurse().

◆ transformRowExpr()

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

Definition at line 2062 of file parse_expr.c.

2063 {
2064  RowExpr *newr;
2065  char fname[16];
2066  int fnum;
2067 
2068  newr = makeNode(RowExpr);
2069 
2070  /* Transform the field expressions */
2071  newr->args = transformExpressionList(pstate, r->args,
2072  pstate->p_expr_kind, allowDefault);
2073 
2074  /* Disallow more columns than will fit in a tuple */
2076  ereport(ERROR,
2077  (errcode(ERRCODE_TOO_MANY_COLUMNS),
2078  errmsg("ROW expressions can have at most %d entries",
2080  parser_errposition(pstate, r->location)));
2081 
2082  /* Barring later casting, we consider the type RECORD */
2083  newr->row_typeid = RECORDOID;
2085 
2086  /* ROW() has anonymous columns, so invent some field names */
2087  newr->colnames = NIL;
2088  for (fnum = 1; fnum <= list_length(newr->args); fnum++)
2089  {
2090  snprintf(fname, sizeof(fname), "f%d", fnum);
2091  newr->colnames = lappend(newr->colnames, makeString(pstrdup(fname)));
2092  }
2093 
2094  newr->location = r->location;
2095 
2096  return (Node *) newr;
2097 }
#define MaxTupleAttributeNumber
Definition: htup_details.h:33
char * pstrdup(const char *in)
Definition: mcxt.c:1483
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
Definition: parse_target.c:221
#define snprintf
Definition: port.h:238
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:588
Oid row_typeid
Definition: primnodes.h:1208
CoercionForm row_format
Definition: primnodes.h:1222
List * colnames
Definition: primnodes.h:1223

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

Referenced by transformExprRecurse(), and transformMultiAssignRef().

◆ transformSubLink()

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

Definition at line 1667 of file parse_expr.c.

1668 {
1669  Node *result = (Node *) sublink;
1670  Query *qtree;
1671  const char *err;
1672 
1673  /*
1674  * Check to see if the sublink is in an invalid place within the query. We
1675  * allow sublinks everywhere in SELECT/INSERT/UPDATE/DELETE/MERGE, but
1676  * generally not in utility statements.
1677  */
1678  err = NULL;
1679  switch (pstate->p_expr_kind)
1680  {
1681  case EXPR_KIND_NONE:
1682  Assert(false); /* can't happen */
1683  break;
1684  case EXPR_KIND_OTHER:
1685  /* Accept sublink here; caller must throw error if wanted */
1686  break;
1687  case EXPR_KIND_JOIN_ON:
1688  case EXPR_KIND_JOIN_USING:
1691  case EXPR_KIND_WHERE:
1692  case EXPR_KIND_POLICY:
1693  case EXPR_KIND_HAVING:
1694  case EXPR_KIND_FILTER:
1704  case EXPR_KIND_MERGE_WHEN:
1705  case EXPR_KIND_GROUP_BY:
1706  case EXPR_KIND_ORDER_BY:
1707  case EXPR_KIND_DISTINCT_ON:
1708  case EXPR_KIND_LIMIT:
1709  case EXPR_KIND_OFFSET:
1710  case EXPR_KIND_RETURNING:
1711  case EXPR_KIND_VALUES:
1713  case EXPR_KIND_CYCLE_MARK:
1714  /* okay */
1715  break;
1718  err = _("cannot use subquery in check constraint");
1719  break;
1722  err = _("cannot use subquery in DEFAULT expression");
1723  break;
1725  err = _("cannot use subquery in index expression");
1726  break;
1728  err = _("cannot use subquery in index predicate");
1729  break;
1731  err = _("cannot use subquery in statistics expression");
1732  break;
1734  err = _("cannot use subquery in transform expression");
1735  break;
1737  err = _("cannot use subquery in EXECUTE parameter");
1738  break;
1740  err = _("cannot use subquery in trigger WHEN condition");
1741  break;
1743  err = _("cannot use subquery in partition bound");
1744  break;
1746  err = _("cannot use subquery in partition key expression");
1747  break;
1749  err = _("cannot use subquery in CALL argument");
1750  break;
1751  case EXPR_KIND_COPY_WHERE:
1752  err = _("cannot use subquery in COPY FROM WHERE condition");
1753  break;
1755  err = _("cannot use subquery in column generation expression");
1756  break;
1757 
1758  /*
1759  * There is intentionally no default: case here, so that the
1760  * compiler will warn if we add a new ParseExprKind without
1761  * extending this switch. If we do see an unrecognized value at
1762  * runtime, the behavior will be the same as for EXPR_KIND_OTHER,
1763  * which is sane anyway.
1764  */
1765  }
1766  if (err)
1767  ereport(ERROR,
1768  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1769  errmsg_internal("%s", err),
1770  parser_errposition(pstate, sublink->location)));
1771 
1772  pstate->p_hasSubLinks = true;
1773 
1774  /*
1775  * OK, let's transform the sub-SELECT.
1776  */
1777  qtree = parse_sub_analyze(sublink->subselect, pstate, NULL, false, true);
1778 
1779  /*
1780  * Check that we got a SELECT. Anything else should be impossible given
1781  * restrictions of the grammar, but check anyway.
1782  */
1783  if (!IsA(qtree, Query) ||
1784  qtree->commandType != CMD_SELECT)
1785  elog(ERROR, "unexpected non-SELECT command in SubLink");
1786 
1787  sublink->subselect = (Node *) qtree;
1788 
1789  if (sublink->subLinkType == EXISTS_SUBLINK)
1790  {
1791  /*
1792  * EXISTS needs no test expression or combining operator. These fields
1793  * should be null already, but make sure.
1794  */
1795  sublink->testexpr = NULL;
1796  sublink->operName = NIL;
1797  }
1798  else if (sublink->subLinkType == EXPR_SUBLINK ||
1799  sublink->subLinkType == ARRAY_SUBLINK)
1800  {
1801  /*
1802  * Make sure the subselect delivers a single column (ignoring resjunk
1803  * targets).
1804  */
1805  if (count_nonjunk_tlist_entries(qtree->targetList) != 1)
1806  ereport(ERROR,
1807  (errcode(ERRCODE_SYNTAX_ERROR),
1808  errmsg("subquery must return only one column"),
1809  parser_errposition(pstate, sublink->location)));
1810 
1811  /*
1812  * EXPR and ARRAY need no test expression or combining operator. These
1813  * fields should be null already, but make sure.
1814  */
1815  sublink->testexpr = NULL;
1816  sublink->operName = NIL;
1817  }
1818  else if (sublink->subLinkType == MULTIEXPR_SUBLINK)
1819  {
1820  /* Same as EXPR case, except no restriction on number of columns */
1821  sublink->testexpr = NULL;
1822  sublink->operName = NIL;
1823  }
1824  else
1825  {
1826  /* ALL, ANY, or ROWCOMPARE: generate row-comparing expression */
1827  Node *lefthand;
1828  List *left_list;
1829  List *right_list;
1830  ListCell *l;
1831 
1832  /*
1833  * If the source was "x IN (select)", convert to "x = ANY (select)".
1834  */
1835  if (sublink->operName == NIL)
1836  sublink->operName = list_make1(makeString("="));
1837 
1838  /*
1839  * Transform lefthand expression, and convert to a list
1840  */
1841  lefthand = transformExprRecurse(pstate, sublink->testexpr);
1842  if (lefthand && IsA(lefthand, RowExpr))
1843  left_list = ((RowExpr *) lefthand)->args;
1844  else
1845  left_list = list_make1(lefthand);
1846 
1847  /*
1848  * Build a list of PARAM_SUBLINK nodes representing the output columns
1849  * of the subquery.
1850  */
1851  right_list = NIL;
1852  foreach(l, qtree->targetList)
1853  {
1854  TargetEntry *tent = (TargetEntry *) lfirst(l);
1855  Param *param;
1856 
1857  if (tent->resjunk)
1858  continue;
1859 
1860  param = makeNode(Param);
1861  param->paramkind = PARAM_SUBLINK;
1862  param->paramid = tent->resno;
1863  param->paramtype = exprType((Node *) tent->expr);
1864  param->paramtypmod = exprTypmod((Node *) tent->expr);
1865  param->paramcollid = exprCollation((Node *) tent->expr);
1866  param->location = -1;
1867 
1868  right_list = lappend(right_list, param);
1869  }
1870 
1871  /*
1872  * We could rely on make_row_comparison_op to complain if the list
1873  * lengths differ, but we prefer to generate a more specific error
1874  * message.
1875  */
1876  if (list_length(left_list) < list_length(right_list))
1877  ereport(ERROR,
1878  (errcode(ERRCODE_SYNTAX_ERROR),
1879  errmsg("subquery has too many columns"),
1880  parser_errposition(pstate, sublink->location)));
1881  if (list_length(left_list) > list_length(right_list))
1882  ereport(ERROR,
1883  (errcode(ERRCODE_SYNTAX_ERROR),
1884  errmsg("subquery has too few columns"),
1885  parser_errposition(pstate, sublink->location)));
1886 
1887  /*
1888  * Identify the combining operator(s) and generate a suitable
1889  * row-comparison expression.
1890  */
1891  sublink->testexpr = make_row_comparison_op(pstate,
1892  sublink->operName,
1893  left_list,
1894  right_list,
1895  sublink->location);
1896  }
1897 
1898  return result;
1899 }
@ CMD_SELECT
Definition: nodes.h:259
Query * parse_sub_analyze(Node *parseTree, ParseState *parentParseState, CommonTableExpr *parentCTE, bool locked_from_parent, bool resolve_unknowns)
Definition: analyze.c:223
@ ARRAY_SUBLINK
Definition: primnodes.h:830
@ EXISTS_SUBLINK
Definition: primnodes.h:824
@ PARAM_SUBLINK
Definition: primnodes.h:304
bool p_hasSubLinks
Definition: parse_node.h:212
CmdType commandType
Definition: parsenodes.h:122
AttrNumber resno
Definition: primnodes.h:1556

References _, ARRAY_SUBLINK, Assert(), CMD_SELECT, Query::commandType, count_nonjunk_tlist_entries(), elog(), 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_CYCLE_MARK, 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_MERGE_WHEN, 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_STATS_EXPRESSION, 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, Param::location, SubLink::location, make_row_comparison_op(), makeNode, makeString(), MULTIEXPR_SUBLINK, NIL, 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(), TargetEntry::resjunk, TargetEntry::resno, SubLink::subLinkType, SubLink::subselect, Query::targetList, SubLink::testexpr, and transformExprRecurse().

Referenced by transformExprRecurse().

◆ transformTypeCast()

static Node * transformTypeCast ( ParseState pstate,
TypeCast tc 
)
static

Definition at line 2519 of file parse_expr.c.

2520 {
2521  Node *result;
2522  Node *arg = tc->arg;
2523  Node *expr;
2524  Oid inputType;
2525  Oid targetType;
2526  int32 targetTypmod;
2527  int location;
2528 
2529  /* Look up the type name first */
2530  typenameTypeIdAndMod(pstate, tc->typeName, &targetType, &targetTypmod);
2531 
2532  /*
2533  * If the subject of the typecast is an ARRAY[] construct and the target
2534  * type is an array type, we invoke transformArrayExpr() directly so that
2535  * we can pass down the type information. This avoids some cases where
2536  * transformArrayExpr() might not infer the correct type. Otherwise, just
2537  * transform the argument normally.
2538  */
2539  if (IsA(arg, A_ArrayExpr))
2540  {
2541  Oid targetBaseType;
2542  int32 targetBaseTypmod;
2543  Oid elementType;
2544 
2545  /*
2546  * If target is a domain over array, work with the base array type
2547  * here. Below, we'll cast the array type to the domain. In the
2548  * usual case that the target is not a domain, the remaining steps
2549  * will be a no-op.
2550  */
2551  targetBaseTypmod = targetTypmod;
2552  targetBaseType = getBaseTypeAndTypmod(targetType, &targetBaseTypmod);
2553  elementType = get_element_type(targetBaseType);
2554  if (OidIsValid(elementType))
2555  {
2556  expr = transformArrayExpr(pstate,
2557  (A_ArrayExpr *) arg,
2558  targetBaseType,
2559  elementType,
2560  targetBaseTypmod);
2561  }
2562  else
2563  expr = transformExprRecurse(pstate, arg);
2564  }
2565  else
2566  expr = transformExprRecurse(pstate, arg);
2567 
2568  inputType = exprType(expr);
2569  if (inputType == InvalidOid)
2570  return expr; /* do nothing if NULL input */
2571 
2572  /*
2573  * Location of the coercion is preferentially the location of the :: or
2574  * CAST symbol, but if there is none then use the location of the type
2575  * name (this can happen in TypeName 'string' syntax, for instance).
2576  */
2577  location = tc->location;
2578  if (location < 0)
2579  location = tc->typeName->location;
2580 
2581  result = coerce_to_target_type(pstate, expr, inputType,
2582  targetType, targetTypmod,
2585  location);
2586  if (result == NULL)
2587  ereport(ERROR,
2588  (errcode(ERRCODE_CANNOT_COERCE),
2589  errmsg("cannot cast type %s to %s",
2590  format_type_be(inputType),
2591  format_type_be(targetType)),
2592  parser_coercion_errposition(pstate, location, expr)));
2593 
2594  return result;
2595 }
signed int int32
Definition: c.h:430
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2496
int parser_coercion_errposition(ParseState *pstate, int coerce_location, Node *input_expr)
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
Definition: parse_type.c:310
TypeName * typeName
Definition: parsenodes.h:337
int location
Definition: parsenodes.h:338
Node * arg
Definition: parsenodes.h:336
int location
Definition: parsenodes.h:238

References arg, TypeCast::arg, COERCE_EXPLICIT_CAST, coerce_to_target_type(), COERCION_EXPLICIT, ereport, errcode(), errmsg(), ERROR, exprType(), format_type_be(), get_element_type(), getBaseTypeAndTypmod(), InvalidOid, IsA, TypeName::location, TypeCast::location, OidIsValid, parser_coercion_errposition(), transformArrayExpr(), transformExprRecurse(), TypeCast::typeName, and typenameTypeIdAndMod().

Referenced by transformExprRecurse().

◆ transformWholeRowRef()

static Node * transformWholeRowRef ( ParseState pstate,
ParseNamespaceItem nsitem,
int  sublevels_up,
int  location 
)
static

Definition at line 2452 of file parse_expr.c.

2454 {
2455  /*
2456  * Build the appropriate referencing node. Normally this can be a
2457  * whole-row Var, but if the nsitem is a JOIN USING alias then it contains
2458  * only a subset of the columns of the underlying join RTE, so that will
2459  * not work. Instead we immediately expand the reference into a RowExpr.
2460  * Since the JOIN USING's common columns are fully determined at this
2461  * point, there seems no harm in expanding it now rather than during
2462  * planning.
2463  *
2464  * Note that if the RTE is a function returning scalar, we create just a
2465  * plain reference to the function value, not a composite containing a
2466  * single column. This is pretty inconsistent at first sight, but it's
2467  * what we've done historically. One argument for it is that "rel" and
2468  * "rel.*" mean the same thing for composite relations, so why not for
2469  * scalar functions...
2470  */
2471  if (nsitem->p_names == nsitem->p_rte->eref)
2472  {
2473  Var *result;
2474 
2475  result = makeWholeRowVar(nsitem->p_rte, nsitem->p_rtindex,
2476  sublevels_up, true);
2477 
2478  /* location is not filled in by makeWholeRowVar */
2479  result->location = location;
2480 
2481  /* mark relation as requiring whole-row SELECT access */
2482  markVarForSelectPriv(pstate, result);
2483 
2484  return (Node *) result;
2485  }
2486  else
2487  {
2488  RowExpr *rowexpr;
2489  List *fields;
2490 
2491  /*
2492  * We want only as many columns as are listed in p_names->colnames,
2493  * and we should use those names not whatever possibly-aliased names
2494  * are in the RTE. We needn't worry about marking the RTE for SELECT
2495  * access, as the common columns are surely so marked already.
2496  */
2497  expandRTE(nsitem->p_rte, nsitem->p_rtindex,
2498  sublevels_up, location, false,
2499  NULL, &fields);
2500  rowexpr = makeNode(RowExpr);
2501  rowexpr->args = list_truncate(fields,
2502  list_length(nsitem->p_names->colnames));
2503  rowexpr->row_typeid = RECORDOID;
2504  rowexpr->row_format = COERCE_IMPLICIT_CAST;
2505  rowexpr->colnames = copyObject(nsitem->p_names->colnames);
2506  rowexpr->location = location;
2507 
2508  return (Node *) rowexpr;
2509  }
2510 }
List * list_truncate(List *list, int new_size)
Definition: list.c:630
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
Definition: makefuncs.c:133
void markVarForSelectPriv(ParseState *pstate, Var *var)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
List * colnames
Definition: primnodes.h:43
RangeTblEntry * p_rte
Definition: parse_node.h:272
Alias * eref
Definition: parsenodes.h:1174
Definition: primnodes.h:205
int location
Definition: primnodes.h:243

References RowExpr::args, COERCE_IMPLICIT_CAST, Alias::colnames, RowExpr::colnames, copyObject, RangeTblEntry::eref, expandRTE(), list_length(), list_truncate(), Var::location, RowExpr::location, makeNode, makeWholeRowVar(), markVarForSelectPriv(), ParseNamespaceItem::p_names, ParseNamespaceItem::p_rte, ParseNamespaceItem::p_rtindex, RowExpr::row_format, and RowExpr::row_typeid.

Referenced by transformColumnRef().

◆ transformXmlExpr()

static Node * transformXmlExpr ( ParseState pstate,
XmlExpr x 
)
static

Definition at line 2188 of file parse_expr.c.

2189 {
2190  XmlExpr *newx;
2191  ListCell *lc;
2192  int i;
2193 
2194  newx = makeNode(XmlExpr);
2195  newx->op = x->op;
2196  if (x->name)
2197  newx->name = map_sql_identifier_to_xml_name(x->name, false, false);
2198  else
2199  newx->name = NULL;
2200  newx->xmloption = x->xmloption;
2201  newx->type = XMLOID; /* this just marks the node as transformed */
2202  newx->typmod = -1;
2203  newx->location = x->location;
2204 
2205  /*
2206  * gram.y built the named args as a list of ResTarget. Transform each,
2207  * and break the names out as a separate list.
2208  */
2209  newx->named_args = NIL;
2210  newx->arg_names = NIL;
2211 
2212  foreach(lc, x->named_args)
2213  {
2214  ResTarget *r = lfirst_node(ResTarget, lc);
2215  Node *expr;
2216  char *argname;
2217 
2218  expr = transformExprRecurse(pstate, r->val);
2219 
2220  if (r->name)
2221  argname = map_sql_identifier_to_xml_name(r->name, false, false);
2222  else if (IsA(r->val, ColumnRef))
2224  true, false);
2225  else
2226  {
2227  ereport(ERROR,
2228  (errcode(ERRCODE_SYNTAX_ERROR),
2229  x->op == IS_XMLELEMENT
2230  ? errmsg("unnamed XML attribute value must be a column reference")
2231  : errmsg("unnamed XML element value must be a column reference"),
2232  parser_errposition(pstate, r->location)));
2233  argname = NULL; /* keep compiler quiet */
2234  }
2235 
2236  /* reject duplicate argnames in XMLELEMENT only */
2237  if (x->op == IS_XMLELEMENT)
2238  {
2239  ListCell *lc2;
2240 
2241  foreach(lc2, newx->arg_names)
2242  {
2243  if (strcmp(argname, strVal(lfirst(lc2))) == 0)
2244  ereport(ERROR,
2245  (errcode(ERRCODE_SYNTAX_ERROR),
2246  errmsg("XML attribute name \"%s\" appears more than once",
2247  argname),
2248  parser_errposition(pstate, r->location)));
2249  }
2250  }
2251 
2252  newx->named_args = lappend(newx->named_args, expr);
2253  newx->arg_names = lappend(newx->arg_names, makeString(argname));
2254  }
2255 
2256  /* The other arguments are of varying types depending on the function */
2257  newx->args = NIL;
2258  i = 0;
2259  foreach(lc, x->args)
2260  {
2261  Node *e = (Node *) lfirst(lc);
2262  Node *newe;
2263 
2264  newe = transformExprRecurse(pstate, e);
2265  switch (x->op)
2266  {
2267  case IS_XMLCONCAT:
2268  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2269  "XMLCONCAT");
2270  break;
2271  case IS_XMLELEMENT:
2272  /* no coercion necessary */
2273  break;
2274  case IS_XMLFOREST:
2275  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2276  "XMLFOREST");
2277  break;
2278  case IS_XMLPARSE:
2279  if (i == 0)
2280  newe = coerce_to_specific_type(pstate, newe, TEXTOID,
2281  "XMLPARSE");
2282  else
2283  newe = coerce_to_boolean(pstate, newe, "XMLPARSE");
2284  break;
2285  case IS_XMLPI:
2286  newe = coerce_to_specific_type(pstate, newe, TEXTOID,
2287  "XMLPI");
2288  break;
2289  case IS_XMLROOT:
2290  if (i == 0)
2291  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2292  "XMLROOT");
2293  else if (i == 1)
2294  newe = coerce_to_specific_type(pstate, newe, TEXTOID,
2295  "XMLROOT");
2296  else
2297  newe = coerce_to_specific_type(pstate, newe, INT4OID,
2298  "XMLROOT");
2299  break;
2300  case IS_XMLSERIALIZE:
2301  /* not handled here */
2302  Assert(false);
2303  break;
2304  case IS_DOCUMENT:
2305  newe = coerce_to_specific_type(pstate, newe, XMLOID,
2306  "IS DOCUMENT");
2307  break;
2308  }
2309  newx->args = lappend(newx->args, newe);
2310  i++;
2311  }
2312 
2313  return (Node *) newx;
2314 }
int x
Definition: isn.c:71
Node * coerce_to_specific_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
char * FigureColname(Node *node)
@ IS_DOCUMENT
Definition: primnodes.h:1315
@ IS_XMLFOREST
Definition: primnodes.h:1310
@ IS_XMLCONCAT
Definition: primnodes.h:1308
@ IS_XMLPI
Definition: primnodes.h:1312
@ IS_XMLPARSE
Definition: primnodes.h:1311
@ IS_XMLSERIALIZE
Definition: primnodes.h:1314
@ IS_XMLROOT
Definition: primnodes.h:1313
@ IS_XMLELEMENT
Definition: primnodes.h:1309
int location
Definition: parsenodes.h:483
Node * val
Definition: parsenodes.h:482
char * name
Definition: parsenodes.h:480
List * args
Definition: primnodes.h:1331
char * name
Definition: primnodes.h:1328
List * arg_names
Definition: primnodes.h:1330
int32 typmod
Definition: primnodes.h:1334
int location
Definition: primnodes.h:1335
List * named_args
Definition: primnodes.h:1329
XmlExprOp op
Definition: primnodes.h:1327
Oid type
Definition: primnodes.h:1333
XmlOptionType xmloption
Definition: primnodes.h:1332
char * map_sql_identifier_to_xml_name(const char *ident, bool fully_escaped, bool escape_period)
Definition: xml.c:2035

References XmlExpr::arg_names, XmlExpr::args, Assert(), coerce_to_boolean(), coerce_to_specific_type(), ereport, errcode(), errmsg(), ERROR, FigureColname(), i, IS_DOCUMENT, IS_XMLCONCAT, IS_XMLELEMENT, IS_XMLFOREST, IS_XMLPARSE, IS_XMLPI, IS_XMLROOT, IS_XMLSERIALIZE, IsA, lappend(), lfirst, lfirst_node, ResTarget::location, XmlExpr::location, makeNode, makeString(), map_sql_identifier_to_xml_name(), ResTarget::name, XmlExpr::name, XmlExpr::named_args, NIL, XmlExpr::op, parser_errposition(), strVal, transformExprRecurse(), XmlExpr::type, XmlExpr::typmod, ResTarget::val, x, and XmlExpr::xmloption.

Referenced by transformExprRecurse().

◆ transformXmlSerialize()

static Node * transformXmlSerialize ( ParseState pstate,
XmlSerialize xs 
)
static

Definition at line 2317 of file parse_expr.c.

2318 {
2319  Node *result;
2320  XmlExpr *xexpr;
2321  Oid targetType;
2322  int32 targetTypmod;
2323 
2324  xexpr = makeNode(XmlExpr);
2325  xexpr->op = IS_XMLSERIALIZE;
2326  xexpr->args = list_make1(coerce_to_specific_type(pstate,
2327  transformExprRecurse(pstate, xs->expr),
2328  XMLOID,
2329  "XMLSERIALIZE"));
2330 
2331  typenameTypeIdAndMod(pstate, xs->typeName, &targetType, &targetTypmod);
2332 
2333  xexpr->xmloption = xs->xmloption;
2334  xexpr->location = xs->location;
2335  /* We actually only need these to be able to parse back the expression. */
2336  xexpr->type = targetType;
2337  xexpr->typmod = targetTypmod;
2338 
2339  /*
2340  * The actual target type is determined this way. SQL allows char and
2341  * varchar as target types. We allow anything that can be cast implicitly
2342  * from text. This way, user-defined text-like data types automatically
2343  * fit in.
2344  */
2345  result = coerce_to_target_type(pstate, (Node *) xexpr,
2346  TEXTOID, targetType, targetTypmod,
2349  -1);
2350  if (result == NULL)
2351  ereport(ERROR,
2352  (errcode(ERRCODE_CANNOT_COERCE),
2353  errmsg("cannot cast XMLSERIALIZE result to %s",
2354  format_type_be(targetType)),
2355  parser_errposition(pstate, xexpr->location)));
2356  return result;
2357 }
@ COERCION_IMPLICIT
Definition: primnodes.h:566
TypeName * typeName
Definition: parsenodes.h:807
Node * expr
Definition: parsenodes.h:806
XmlOptionType xmloption
Definition: parsenodes.h:805

References XmlExpr::args, COERCE_IMPLICIT_CAST, coerce_to_specific_type(), coerce_to_target_type(), COERCION_IMPLICIT, ereport, errcode(), errmsg(), ERROR, XmlSerialize::expr, format_type_be(), IS_XMLSERIALIZE, list_make1, XmlSerialize::location, XmlExpr::location, makeNode, XmlExpr::op, parser_errposition(), transformExprRecurse(), XmlExpr::type, XmlSerialize::typeName, typenameTypeIdAndMod(), XmlExpr::typmod, XmlSerialize::xmloption, and XmlExpr::xmloption.

Referenced by transformExprRecurse().

◆ unknown_attribute()

static void unknown_attribute ( ParseState pstate,
Node relref,
const char *  attname,
int  location 
)
static

Definition at line 314 of file parse_expr.c.

316 {
317  RangeTblEntry *rte;
318 
319  if (IsA(relref, Var) &&
320  ((Var *) relref)->varattno == InvalidAttrNumber)
321  {
322  /* Reference the RTE by alias not by actual table name */
323  rte = GetRTEByRangeTablePosn(pstate,
324  ((Var *) relref)->varno,
325  ((Var *) relref)->varlevelsup);
326  ereport(ERROR,
327  (errcode(ERRCODE_UNDEFINED_COLUMN),
328  errmsg("column %s.%s does not exist",
329  rte->eref->aliasname, attname),
330  parser_errposition(pstate, location)));
331  }
332  else
333  {
334  /* Have to do it by reference to the type of the expression */
335  Oid relTypeId = exprType(relref);
336 
337  if (ISCOMPLEX(relTypeId))
338  ereport(ERROR,
339  (errcode(ERRCODE_UNDEFINED_COLUMN),
340  errmsg("column \"%s\" not found in data type %s",
341  attname, format_type_be(relTypeId)),
342  parser_errposition(pstate, location)));
343  else if (relTypeId == RECORDOID)
344  ereport(ERROR,
345  (errcode(ERRCODE_UNDEFINED_COLUMN),
346  errmsg("could not identify column \"%s\" in record data type",
347  attname),
348  parser_errposition(pstate, location)));
349  else
350  ereport(ERROR,
351  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
352  errmsg("column notation .%s applied to type %s, "
353  "which is not a composite type",
354  attname, format_type_be(relTypeId)),
355  parser_errposition(pstate, location)));
356  }
357 }
#define InvalidAttrNumber
Definition: attnum.h:23
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
#define ISCOMPLEX(typeid)
Definition: parse_type.h:58
NameData attname
Definition: pg_attribute.h:41
char * aliasname
Definition: primnodes.h:42

References Alias::aliasname, attname, RangeTblEntry::eref, ereport, errcode(), errmsg(), ERROR, exprType(), format_type_be(), GetRTEByRangeTablePosn(), InvalidAttrNumber, IsA, ISCOMPLEX, and parser_errposition().

Referenced by transformIndirection().

Variable Documentation

◆ Transform_null_equals

bool Transform_null_equals = false

Definition at line 42 of file parse_expr.c.

Referenced by transformAExprOp().