38#include "utils/fmgroids.h"
76 int sublevels_up,
int location);
96 List **passing_values,
List **passing_names);
102 List *largs,
List *rargs,
int location);
160 case T_A_Indirection:
173 case T_CollateClause:
215 elog(
ERROR,
"unrecognized A_Expr kind: %d",
a->kind);
230 case T_MultiAssignRef:
238 case T_MergeSupportFunc:
272 case T_SQLValueFunction:
300 case T_CurrentOfExpr:
310 (
errcode(ERRCODE_SYNTAX_ERROR),
311 errmsg(
"DEFAULT is not allowed in this context"),
329 result = (
Node *) expr;
333 case T_JsonObjectConstructor:
337 case T_JsonArrayConstructor:
341 case T_JsonArrayQueryConstructor:
345 case T_JsonObjectAgg:
353 case T_JsonIsPredicate:
357 case T_JsonParseExpr:
361 case T_JsonScalarExpr:
365 case T_JsonSerializeExpr:
400 ((
Var *) relref)->varno,
401 ((
Var *) relref)->varlevelsup);
403 (
errcode(ERRCODE_UNDEFINED_COLUMN),
404 errmsg(
"column %s.%s does not exist",
405 rte->eref->aliasname,
attname),
415 (
errcode(ERRCODE_UNDEFINED_COLUMN),
416 errmsg(
"column \"%s\" not found in data type %s",
419 else if (relTypeId == RECORDOID)
421 (
errcode(ERRCODE_UNDEFINED_COLUMN),
422 errmsg(
"could not identify column \"%s\" in record data type",
427 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
428 errmsg(
"column notation .%s applied to type %s, "
429 "which is not a composite type",
449 foreach(
i,
ind->indirection)
454 subscripts =
lappend(subscripts, n);
458 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
459 errmsg(
"row expansion via \"*\" is not supported here"),
485 if (newresult == NULL)
511 char *nspname = NULL;
513 char *colname = NULL;
522 } crerr = CRERR_NO_COLUMN;
582 err =
_(
"cannot use column reference in DEFAULT expression");
585 err =
_(
"cannot use column reference in partition bound expression");
598 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
682 crerr = CRERR_NO_RTE;
729 crerr = CRERR_NO_RTE;
778 crerr = CRERR_WRONG_DB;
788 crerr = CRERR_NO_RTE;
821 crerr = CRERR_TOO_MANY;
841 else if (hookresult != NULL)
843 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
844 errmsg(
"column reference \"%s\" is ambiguous",
856 case CRERR_NO_COLUMN:
865 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
866 errmsg(
"cross-database references are not implemented: %s",
872 (
errcode(ERRCODE_SYNTAX_ERROR),
873 errmsg(
"improper qualified name (too many dotted names): %s",
899 (
errcode(ERRCODE_UNDEFINED_PARAMETER),
923 Node *lexpr =
a->lexpr;
924 Node *rexpr =
a->rexpr;
965 s->operName =
a->name;
1032 Node *lexpr =
a->lexpr;
1033 Node *rexpr =
a->rexpr;
1097 if (result->opresulttype != BOOLOID)
1099 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1101 errmsg(
"%s requires = operator to yield boolean",
"NULLIF"),
1103 if (result->opretset)
1105 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1107 errmsg(
"%s must not return a set",
"NULLIF"),
1120 return (
Node *) result;
1126 Node *result = NULL;
1154 rexprs = rvars = rnonvars =
NIL;
1155 foreach(l, (
List *)
a->rexpr)
1159 rexprs =
lappend(rexprs, rexpr);
1161 rvars =
lappend(rvars, rexpr);
1163 rnonvars =
lappend(rnonvars, rexpr);
1197 if (
OidIsValid(scalar_type) && scalar_type != RECORDOID)
1211 foreach(l, rnonvars)
1218 aexprs =
lappend(aexprs, rexpr);
1221 newa->array_typeid = array_type;
1223 newa->element_typeid = scalar_type;
1225 newa->multidims =
false;
1367 elog(
ERROR,
"unrecognized A_Expr kind: %d",
a->kind);
1386 while (parent_pstate &&
1392 errcode(ERRCODE_SYNTAX_ERROR),
1393 errmsg(
"MERGE_ACTION() can only be used in the RETURNING list of a MERGE command"),
1419 elog(
ERROR,
"unrecognized boolop: %d", (
int)
a->boolop);
1424 foreach(lc,
a->args)
1459 if (
fn->agg_within_group)
1462 foreach(
args,
fn->agg_order)
1493 if (maref->
colno == 1)
1516 (
errcode(ERRCODE_SYNTAX_ERROR),
1517 errmsg(
"number of columns does not match number of values"),
1548 (
errcode(ERRCODE_SYNTAX_ERROR),
1549 errmsg(
"number of columns does not match number of values"),
1562 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1563 errmsg(
"source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"),
1600 return (
Node *) param;
1625 elog(
ERROR,
"unexpected expr type in multiassign list");
1690 (
Node *) placeholder,
1704 newargs =
lappend(newargs, neww);
1708 newc->
args = newargs;
1711 defresult = (
Node *)
c->defresult;
1712 if (defresult == NULL)
1718 defresult = (
Node *) n;
1731 newc->casetype = ptype;
1742 foreach(l, newc->
args)
1756 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1758 errmsg(
"set-returning functions are not allowed in %s",
1760 errhint(
"You might be able to move the set-returning function into a LATERAL FROM item."),
1766 return (
Node *) newc;
1822 err =
_(
"cannot use subquery in check constraint");
1826 err =
_(
"cannot use subquery in DEFAULT expression");
1829 err =
_(
"cannot use subquery in index expression");
1832 err =
_(
"cannot use subquery in index predicate");
1835 err =
_(
"cannot use subquery in statistics expression");
1838 err =
_(
"cannot use subquery in transform expression");
1841 err =
_(
"cannot use subquery in EXECUTE parameter");
1844 err =
_(
"cannot use subquery in trigger WHEN condition");
1847 err =
_(
"cannot use subquery in partition bound");
1850 err =
_(
"cannot use subquery in partition key expression");
1853 err =
_(
"cannot use subquery in CALL argument");
1856 err =
_(
"cannot use subquery in COPY FROM WHERE condition");
1859 err =
_(
"cannot use subquery in column generation expression");
1872 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1889 elog(
ERROR,
"unexpected non-SELECT command in SubLink");
1900 sublink->operName =
NIL;
1911 (
errcode(ERRCODE_SYNTAX_ERROR),
1912 errmsg(
"subquery must return only one column"),
1920 sublink->operName =
NIL;
1926 sublink->operName =
NIL;
1939 if (sublink->operName ==
NIL)
1947 left_list = ((
RowExpr *) lefthand)->args;
1972 right_list =
lappend(right_list, param);
1982 (
errcode(ERRCODE_SYNTAX_ERROR),
1983 errmsg(
"subquery has too many columns"),
1987 (
errcode(ERRCODE_SYNTAX_ERROR),
1988 errmsg(
"subquery has too few columns"),
2029 newa->multidims =
false;
2048 newa->multidims =
true;
2059 newa->multidims =
true;
2062 newelems =
lappend(newelems, newe);
2075 coerce_type = (newa->multidims ? array_type : element_type);
2081 if (newelems ==
NIL)
2083 (
errcode(ERRCODE_INDETERMINATE_DATATYPE),
2084 errmsg(
"cannot determine type of empty array"),
2085 errhint(
"Explicitly cast to the desired type, "
2086 "for example ARRAY[]::integer[]."),
2092 if (newa->multidims)
2098 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2099 errmsg(
"could not find element type for data type %s",
2109 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2110 errmsg(
"could not find array type for data type %s",
2114 coerce_hard =
false;
2143 (
errcode(ERRCODE_CANNOT_COERCE),
2144 errmsg(
"cannot cast type %s to %s",
2153 newcoercedelems =
lappend(newcoercedelems, newe);
2156 newa->array_typeid = array_type;
2158 newa->element_typeid = element_type;
2162 return (
Node *) newa;
2181 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2182 errmsg(
"ROW expressions can have at most %d entries",
2187 newr->row_typeid = RECORDOID;
2191 newr->colnames =
NIL;
2194 snprintf(fname,
sizeof(fname),
"f%d", fnum);
2200 return (
Node *) newr;
2212 foreach(
args,
c->args)
2218 newargs =
lappend(newargs, newe);
2225 foreach(
args, newargs)
2233 newcoercedargs =
lappend(newcoercedargs, newe);
2239 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2241 errmsg(
"set-returning functions are not allowed in %s",
2243 errhint(
"You might be able to move the set-returning function into a LATERAL FROM item."),
2247 newc->
args = newcoercedargs;
2249 return (
Node *) newc;
2268 newargs =
lappend(newargs, newe);
2275 foreach(
args, newargs)
2283 newcoercedargs =
lappend(newcoercedargs, newe);
2286 newm->
args = newcoercedargs;
2288 return (
Node *) newm;
2301 svf->type = DATEOID;
2304 svf->type = TIMETZOID;
2307 svf->type = TIMETZOID;
2311 svf->type = TIMESTAMPTZOID;
2314 svf->type = TIMESTAMPTZOID;
2318 svf->type = TIMEOID;
2321 svf->type = TIMEOID;
2325 svf->type = TIMESTAMPOID;
2328 svf->type = TIMESTAMPOID;
2337 svf->type = NAMEOID;
2341 return (
Node *) svf;
2357 newx->xmloption =
x->xmloption;
2358 newx->type = XMLOID;
2367 newx->arg_names =
NIL;
2369 foreach(lc,
x->named_args)
2385 (
errcode(ERRCODE_SYNTAX_ERROR),
2387 ?
errmsg(
"unnamed XML attribute value must be a column reference")
2388 :
errmsg(
"unnamed XML element value must be a column reference"),
2398 foreach(lc2, newx->arg_names)
2402 (
errcode(ERRCODE_SYNTAX_ERROR),
2403 errmsg(
"XML attribute name \"%s\" appears more than once",
2416 foreach(lc,
x->args)
2470 return (
Node *) newx;
2494 xexpr->type = targetType;
2495 xexpr->typmod = targetTypmod;
2504 TEXTOID, targetType, targetTypmod,
2510 (
errcode(ERRCODE_CANNOT_COERCE),
2511 errmsg(
"cannot cast XMLSERIALIZE result to %s",
2520 const char *clausename;
2522 switch (
b->booltesttype)
2525 clausename =
"IS TRUE";
2528 clausename =
"IS NOT TRUE";
2531 clausename =
"IS FALSE";
2534 clausename =
"IS NOT FALSE";
2537 clausename =
"IS UNKNOWN";
2540 clausename =
"IS NOT UNKNOWN";
2543 elog(
ERROR,
"unrecognized booltesttype: %d",
2544 (
int)
b->booltesttype);
2589 if (node != NULL &&
IsA(node,
Param))
2603 return (
Node *) cexpr;
2611 int sublevels_up,
int location)
2634 sublevels_up,
true);
2645 return (
Node *) result;
2659 sublevels_up, location,
false,
2664 rowexpr->row_typeid = RECORDOID;
2671 return (
Node *) rowexpr;
2705 int32 targetBaseTypmod;
2714 targetBaseTypmod = targetTypmod;
2745 targetType, targetTypmod,
2751 (
errcode(ERRCODE_CANNOT_COERCE),
2752 errmsg(
"cannot cast type %s to %s",
2782 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2783 errmsg(
"collations are not supported by type %s",
2790 return (
Node *) newc;
2807 List *largs,
List *rargs,
int location)
2816 List **opinfo_lists;
2824 (
errcode(ERRCODE_SYNTAX_ERROR),
2825 errmsg(
"unequal number of entries in row expressions"),
2834 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2835 errmsg(
"cannot compare rows of zero length"),
2857 if (
cmp->opresulttype != BOOLOID)
2859 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2860 errmsg(
"row comparison operator must yield type boolean, "
2866 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2867 errmsg(
"row comparison operator must not return a set"),
2902 foreach(
j, opinfo_lists[
i])
2909 strats = this_strats;
2925 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2926 errmsg(
"could not determine interpretation of row comparison operator %s",
2928 errhint(
"Row comparison operators must be associated with btree operator families."),
2947 for (
i = 0;
i < nopers;
i++)
2952 foreach(
j, opinfo_lists[
i])
2966 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2967 errmsg(
"could not determine interpretation of row comparison operator %s",
2969 errdetail(
"There are multiple equally-plausible candidates."),
2993 rcexpr->opnos = opnos;
2994 rcexpr->opfamilies = opfamilies;
2995 rcexpr->inputcollids =
NIL;
2996 rcexpr->
largs = largs;
2997 rcexpr->
rargs = rargs;
2999 return (
Node *) rcexpr;
3012 Node *result = NULL;
3020 (
errcode(ERRCODE_SYNTAX_ERROR),
3021 errmsg(
"unequal number of entries in row expressions"),
3059 if (((
OpExpr *) result)->opresulttype != BOOLOID)
3061 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3063 errmsg(
"%s requires = operator to yield boolean",
3064 "IS DISTINCT FROM"),
3066 if (((
OpExpr *) result)->opretset)
3068 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3070 errmsg(
"%s must not return a set",
"IS DISTINCT FROM"),
3098 nt->argisrow =
false;
3116 return "invalid expression context";
3118 return "extension expression";
3122 return "JOIN/USING";
3124 return "sub-SELECT in FROM";
3126 return "function in FROM";
3136 return "window PARTITION BY";
3138 return "window ORDER BY";
3140 return "window RANGE";
3142 return "window ROWS";
3144 return "window GROUPS";
3153 return "MERGE WHEN";
3159 return "DISTINCT ON";
3177 return "index expression";
3179 return "index predicate";
3181 return "statistics expression";
3189 return "partition bound";
3191 return "PARTITION BY";
3197 return "GENERATED AS";
3208 return "unrecognized expression kind";
3266 return (
Node *) fexpr;
3280 Oid targettype,
bool isarg)
3288 bool typispreferred;
3303 errcode(ERRCODE_DATATYPE_MISMATCH),
3304 errmsg(
"JSON ENCODING clause is only allowed for bytea input type"),
3307 if (exprtype == JSONOID || exprtype == JSONBOID)
3335 case TIMESTAMPTZOID:
3339 if (typcategory == TYPCATEGORY_STRING)
3347 else if (exprtype == JSONOID || exprtype == JSONBOID)
3353 (
OidIsValid(targettype) && exprtype != targettype))
3356 bool only_allow_cast =
OidIsValid(targettype);
3364 exprtype != BYTEAOID && typcategory != TYPCATEGORY_STRING)
3366 errcode(ERRCODE_DATATYPE_MISMATCH),
3368 errmsg(
"cannot use non-string types with implicit FORMAT JSON clause") :
3369 errmsg(
"cannot use non-string types with explicit FORMAT JSON clause"),
3400 if (only_allow_cast)
3402 (
errcode(ERRCODE_CANNOT_COERCE),
3403 errmsg(
"cannot cast type %s to %s",
3408 fnoid = targettype == JSONOID ? F_TO_JSON : F_TO_JSONB;
3414 coerced = (
Node *) fexpr;
3417 if (coerced == expr)
3441 Oid targettype,
bool allow_format_for_non_strings)
3443 if (!allow_format_for_non_strings &&
3445 (targettype != BYTEAOID &&
3446 targettype != JSONOID &&
3447 targettype != JSONBOID))
3450 bool typispreferred;
3454 if (typcategory != TYPCATEGORY_STRING)
3456 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3458 errmsg(
"cannot use JSON format with non-string output types"));
3466 if (targettype != BYTEAOID &&
3469 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3471 errmsg(
"cannot set JSON encoding for non-bytea output types"));
3475 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3476 errmsg(
"unsupported JSON encoding"),
3477 errhint(
"Only UTF8 JSON encoding is supported."),
3511 if (
output->typeName->setof)
3513 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3514 errmsg(
"returning SETOF types is not supported in SQL/JSON functions"));
3518 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3519 errmsg(
"returning pseudo-types is not supported in SQL/JSON functions"));
3545 bool have_jsonb =
false;
3552 have_jsonb |= typid == JSONBOID;
3560 returning->
typid = JSONBOID;
3566 returning->
typid = JSONOID;
3598 returning->
typid == BYTEAOID)
3611 return (
Node *) fexpr;
3629 if (!
res && report_error)
3631 errcode(ERRCODE_CANNOT_COERCE),
3632 errmsg(
"cannot cast type %s to %s",
3646 bool unique,
bool absent_on_null,
int location)
3653 jsctor->
func = fexpr;
3674 placeholder = (
Node *) cte;
3685 placeholder = (
Node *) cte;
3690 if (coercion != placeholder)
3693 return (
Node *) jsctor;
3715 foreach(lc, ctor->
exprs)
3761 errcode(ERRCODE_SYNTAX_ERROR),
3762 errmsg(
"subquery must return only one column"),
3783 target->
name = NULL;
3791 range->lateral =
false;
3793 range->alias = alias;
3801 sublink->operName =
NIL;
3814 Oid aggfnoid,
Oid aggtype,
3816 bool unique,
bool absent_on_null)
3831 wfunc->wintype = aggtype;
3835 wfunc->runCondition =
NIL;
3837 wfunc->winstar =
false;
3838 wfunc->winagg =
true;
3846 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3847 errmsg(
"aggregate ORDER BY is not implemented for window functions"),
3853 node = (
Node *) wfunc;
3860 aggref->aggtype = aggtype;
3868 aggref->aggstar =
false;
3869 aggref->aggvariadic =
false;
3870 aggref->aggkind = AGGKIND_NORMAL;
3871 aggref->aggpresorted =
false;
3875 aggref->aggtransno = -1;
3880 node = (
Node *) aggref;
3884 returning, unique, absent_on_null,
3921 aggfnoid = F_JSONB_OBJECT_AGG_UNIQUE_STRICT;
3923 aggfnoid = F_JSONB_OBJECT_AGG_STRICT;
3925 aggfnoid = F_JSONB_OBJECT_AGG_UNIQUE;
3927 aggfnoid = F_JSONB_OBJECT_AGG;
3935 aggfnoid = F_JSON_OBJECT_AGG_UNIQUE_STRICT;
3937 aggfnoid = F_JSON_OBJECT_AGG_STRICT;
3939 aggfnoid = F_JSON_OBJECT_AGG_UNIQUE;
3941 aggfnoid = F_JSON_OBJECT_AGG;
3947 args, aggfnoid, aggtype,
3977 aggfnoid = agg->
absent_on_null ? F_JSONB_AGG_STRICT : F_JSONB_AGG;
4011 foreach(lc, ctor->
exprs)
4034 Node *expr = raw_expr;
4039 if (*exprtype == BYTEAOID)
4045 *exprtype = TEXTOID;
4048 expr = (
Node *) jve;
4053 bool typispreferred;
4057 if (*exprtype == UNKNOWNOID || typcategory == TYPCATEGORY_STRING)
4063 *exprtype = TEXTOID;
4068 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4070 errmsg(
"cannot use JSON FORMAT ENCODING clause for non-bytea input types")));
4087 if (exprtype != TEXTOID && exprtype != JSONOID && exprtype != JSONBOID)
4089 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4090 errmsg(
"cannot use type %s in IS JSON predicate",
4113 if (returning->
typid != JSONOID && returning->
typid != JSONBOID)
4115 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4116 errmsg(
"cannot use RETURNING type %s in %s",
4123 Oid targettype = JSONOID;
4128 returning->
typid = targettype;
4162 if (arg_type != TEXTOID)
4164 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4165 errmsg(
"cannot use non-string types with WITH UNIQUE KEYS clause"),
4203 returning,
false,
false, jsexpr->
location);
4226 if (returning->
typid != BYTEAOID)
4229 bool typispreferred;
4233 if (typcategory != TYPCATEGORY_STRING)
4235 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4236 errmsg(
"cannot use RETURNING type %s in %s",
4238 "JSON_SERIALIZE()"),
4239 errhint(
"Try returning a string type or bytea.")));
4247 returning->
typid = TEXTOID;
4252 NULL, returning,
false,
false, expr->
location);
4264 const char *func_name = NULL;
4270 func_name =
"JSON_EXISTS";
4274 func_name =
"JSON_QUERY";
4278 func_name =
"JSON_VALUE";
4282 func_name =
"JSON_TABLE";
4286 elog(
ERROR,
"invalid JsonFuncExpr op %d", (
int) func->
op);
4303 errcode(ERRCODE_SYNTAX_ERROR),
4304 errmsg(
"cannot specify FORMAT JSON in RETURNING clause of %s()",
4316 errcode(ERRCODE_SYNTAX_ERROR),
4317 errmsg(
"SQL/JSON QUOTES behavior must not be specified when WITH WRAPPER is used"),
4329 errcode(ERRCODE_SYNTAX_ERROR),
4331 errmsg(
"invalid %s behavior",
"ON EMPTY"),
4334 errdetail(
"Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for %s.",
4335 "ON EMPTY",
"JSON_QUERY()"),
4339 errcode(ERRCODE_SYNTAX_ERROR),
4341 errmsg(
"invalid %s behavior for column \"%s\"",
4344 errdetail(
"Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for formatted columns.",
4358 errcode(ERRCODE_SYNTAX_ERROR),
4360 errmsg(
"invalid %s behavior",
"ON ERROR"),
4363 errdetail(
"Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for %s.",
4364 "ON ERROR",
"JSON_QUERY()"),
4368 errcode(ERRCODE_SYNTAX_ERROR),
4370 errmsg(
"invalid %s behavior for column \"%s\"",
4373 errdetail(
"Only ERROR, NULL, EMPTY ARRAY, EMPTY OBJECT, or DEFAULT expression is allowed in %s for formatted columns.",
4389 errcode(ERRCODE_SYNTAX_ERROR),
4391 errmsg(
"invalid %s behavior",
"ON ERROR"),
4392 errdetail(
"Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in %s for %s.",
4393 "ON ERROR",
"JSON_EXISTS()"),
4397 errcode(ERRCODE_SYNTAX_ERROR),
4399 errmsg(
"invalid %s behavior for column \"%s\"",
4402 errdetail(
"Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in %s for EXISTS columns.",
4415 errcode(ERRCODE_SYNTAX_ERROR),
4417 errmsg(
"invalid %s behavior",
"ON EMPTY"),
4420 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in %s for %s.",
4421 "ON EMPTY",
"JSON_VALUE()"),
4425 errcode(ERRCODE_SYNTAX_ERROR),
4427 errmsg(
"invalid %s behavior for column \"%s\"",
4430 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in %s for scalar columns.",
4441 errcode(ERRCODE_SYNTAX_ERROR),
4443 errmsg(
"invalid %s behavior",
"ON ERROR"),
4446 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in %s for %s.",
4447 "ON ERROR",
"JSON_VALUE()"),
4451 errcode(ERRCODE_SYNTAX_ERROR),
4453 errmsg(
"invalid %s behavior for column \"%s\"",
4456 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in %s for scalar columns.",
4464 jsexpr->
op = func->
op;
4483 if (path_spec == NULL)
4485 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4486 errmsg(
"JSON path expression must be of type %s, not of type %s",
4526 ret->
typid = JSONBOID;
4615 elog(
ERROR,
"invalid JsonFuncExpr op %d", (
int) func->
op);
4619 return (
Node *) jsexpr;
4628 List **passing_values,
List **passing_names)
4632 *passing_values =
NIL;
4633 *passing_names =
NIL;
4642 *passing_values =
lappend(*passing_values, expr);
4667 case T_CoerceToDomain:
4668 case T_ArrayCoerceExpr:
4669 case T_ConvertRowtypeExpr:
4691 bool coerce_at_runtime =
false;
4696 btype = behavior->
btype;
4703 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4704 errmsg(
"can only specify a constant, non-aggregate function, or operator expression for DEFAULT"),
4708 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4709 errmsg(
"DEFAULT expression must not contain column references"),
4713 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4714 errmsg(
"DEFAULT expression must not return a set"),
4735 bool isnull = (
IsA(expr,
Const) && ((
Const *) expr)->constisnull);
4742 coerce_at_runtime =
true;
4774 (typcategory == TYPCATEGORY_STRING ||
4775 typcategory == TYPCATEGORY_BITSTRING) ?
4781 if (coerced_expr == NULL)
4789 errcode(ERRCODE_CANNOT_COERCE),
4790 errmsg(
"cannot cast behavior expression of type %s to %s",
4793 errhint(
"You will need to explicitly cast the expression to type %s.",
4798 errcode(ERRCODE_CANNOT_COERCE),
4799 errmsg(
"cannot cast behavior expression of type %s to %s",
4805 expr = coerced_expr;
4810 behavior->
expr = expr;
4814 behavior->
coerce = coerce_at_runtime;
4827 Oid typid = JSONBOID;
4829 bool isbyval =
false;
4830 bool isnull =
false;
4874 elog(
ERROR,
"unrecognized SQL/JSON behavior %d", btype);
4879 con->location = location;
4881 return (
Node *) con;
#define InvalidAttrNumber
int32 anytimestamp_typmod_check(bool istz, int32 typmod)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define Assert(condition)
#define OidIsValid(objectId)
int32 anytime_typmod_check(bool istz, int32 typmod)
char * get_database_name(Oid dbid)
static void PGresult * res
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void err(int eval, const char *fmt,...)
#define DirectFunctionCall1(func, arg1)
#define MaxTupleAttributeNumber
if(TABLE==NULL||TABLE_index==NULL)
Datum jsonb_in(PG_FUNCTION_ARGS)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * lappend_oid(List *list, Oid datum)
List * lcons(void *datum, List *list)
List * list_delete_last(List *list)
List * list_truncate(List *list, int new_size)
List * get_op_btree_interpretation(Oid opno)
Oid get_element_type(Oid typid)
bool type_is_rowtype(Oid typid)
bool type_is_collatable(Oid typid)
char get_typtype(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid getBaseType(Oid typid)
Oid get_array_type(Oid typid)
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
#define type_is_array(typid)
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
JsonBehavior * makeJsonBehavior(JsonBehaviorType btype, Node *expr, int location)
A_Expr * makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, int location)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
Node * makeBoolConst(bool value, bool isnull)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
JsonValueExpr * makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr, JsonFormat *format)
JsonFormat * makeJsonFormat(JsonFormatType type, JsonEncoding encoding, int location)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Node * makeJsonIsPredicate(Node *expr, JsonFormat *format, JsonValueType item_type, bool unique_keys, int location)
char * pstrdup(const char *in)
void namestrcpy(Name name, const char *str)
char * NameListToString(const List *names)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
int exprLocation(const Node *expr)
bool expression_returns_set(Node *clause)
#define expression_tree_walker(n, w, c)
#define IsA(nodeptr, _type_)
#define NodeSetTag(nodeptr, t)
#define castNode(_type_, nodeptr)
Node * transformGroupingFunc(ParseState *pstate, GroupingFunc *p)
void transformWindowFuncCall(ParseState *pstate, WindowFunc *wfunc, WindowDef *windef)
void transformAggregateCall(ParseState *pstate, Aggref *agg, List *args, List *aggorder, bool agg_distinct)
Node * transformWhereClause(ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
TYPCATEGORY TypeCategory(Oid type)
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
bool verify_common_type(Oid common_type, List *exprs)
int parser_coercion_errposition(ParseState *pstate, int coerce_location, Node *input_expr)
Node * coerce_to_specific_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
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)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
void assign_expr_collations(ParseState *pstate, Node *expr)
static Node * transformMergeSupportFunc(ParseState *pstate, MergeSupportFunc *f)
static Node * make_nulltest_from_distinct(ParseState *pstate, A_Expr *distincta, Node *arg)
static void unknown_attribute(ParseState *pstate, Node *relref, const char *attname, int location)
static Node * transformJsonArrayConstructor(ParseState *pstate, JsonArrayConstructor *ctor)
static Node * transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr)
static Node * transformAExprOpAll(ParseState *pstate, A_Expr *a)
static Node * makeJsonByteaToTextConversion(Node *expr, JsonFormat *format, int location)
static Node * transformJsonParseExpr(ParseState *pstate, JsonParseExpr *jsexpr)
static Node * transformAExprIn(ParseState *pstate, A_Expr *a)
static JsonReturning * transformJsonOutput(ParseState *pstate, const JsonOutput *output, bool allow_format)
static void checkJsonOutputFormat(ParseState *pstate, const JsonFormat *format, Oid targettype, bool allow_format_for_non_strings)
static Node * transformJsonParseArg(ParseState *pstate, Node *jsexpr, JsonFormat *format, Oid *exprtype)
static Node * makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type, List *args, Expr *fexpr, JsonReturning *returning, bool unique, bool absent_on_null, int location)
static Node * transformAExprOpAny(ParseState *pstate, A_Expr *a)
static Node * transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
static Node * transformAExprNullIf(ParseState *pstate, A_Expr *a)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
static Node * transformJsonScalarExpr(ParseState *pstate, JsonScalarExpr *jsexpr)
static bool exprIsNullConstant(Node *arg)
static Expr * make_distinct_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, int location)
static Node * transformJsonArrayQueryConstructor(ParseState *pstate, JsonArrayQueryConstructor *ctor)
static Node * transformSQLValueFunction(ParseState *pstate, SQLValueFunction *svf)
static Node * transformColumnRef(ParseState *pstate, ColumnRef *cref)
static Node * transformCollateClause(ParseState *pstate, CollateClause *c)
static Node * transformBoolExpr(ParseState *pstate, BoolExpr *a)
static bool ValidJsonBehaviorDefaultExpr(Node *expr, void *context)
static Node * transformFuncCall(ParseState *pstate, FuncCall *fn)
static JsonReturning * transformJsonConstructorOutput(ParseState *pstate, JsonOutput *output, List *args)
static Node * transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
static Node * transformJsonAggConstructor(ParseState *pstate, JsonAggConstructor *agg_ctor, JsonReturning *returning, List *args, Oid aggfnoid, Oid aggtype, JsonConstructorType ctor_type, bool unique, bool absent_on_null)
static Node * transformCoalesceExpr(ParseState *pstate, CoalesceExpr *c)
bool Transform_null_equals
static Node * transformSubLink(ParseState *pstate, SubLink *sublink)
static void transformJsonPassingArgs(ParseState *pstate, const char *constructName, JsonFormatType format, List *args, List **passing_values, List **passing_names)
static Node * transformJsonObjectConstructor(ParseState *pstate, JsonObjectConstructor *ctor)
static Node * make_row_comparison_op(ParseState *pstate, List *opname, List *largs, List *rargs, int location)
static JsonReturning * transformJsonReturning(ParseState *pstate, JsonOutput *output, const char *fname)
static Node * transformAExprOp(ParseState *pstate, A_Expr *a)
static Node * GetJsonBehaviorConst(JsonBehaviorType btype, int location)
static JsonBehavior * transformJsonBehavior(ParseState *pstate, JsonBehavior *behavior, JsonBehaviorType default_behavior, JsonReturning *returning)
static Node * transformJsonArrayAgg(ParseState *pstate, JsonArrayAgg *agg)
static Node * transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, Oid array_type, Oid element_type, int32 typmod)
static Node * transformMultiAssignRef(ParseState *pstate, MultiAssignRef *maref)
static Node * transformBooleanTest(ParseState *pstate, BooleanTest *b)
static Node * make_row_distinct_op(ParseState *pstate, List *opname, RowExpr *lrow, RowExpr *rrow, int location)
static Node * transformTypeCast(ParseState *pstate, TypeCast *tc)
static Node * transformJsonValueExpr(ParseState *pstate, const char *constructName, JsonValueExpr *ve, JsonFormatType default_format, Oid targettype, bool isarg)
static Node * transformParamRef(ParseState *pstate, ParamRef *pref)
static Node * transformCaseExpr(ParseState *pstate, CaseExpr *c)
static Node * transformIndirection(ParseState *pstate, A_Indirection *ind)
static Node * coerceJsonFuncExpr(ParseState *pstate, Node *expr, const JsonReturning *returning, bool report_error)
static Node * transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr)
static Node * transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
static Node * transformXmlExpr(ParseState *pstate, XmlExpr *x)
static Const * getJsonEncodingConst(JsonFormat *format)
static Node * transformAExprBetween(ParseState *pstate, A_Expr *a)
static Node * transformWholeRowRef(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location)
const char * ParseExprKindName(ParseExprKind exprKind)
static Node * transformJsonFuncExpr(ParseState *pstate, JsonFuncExpr *func)
static Node * transformJsonIsPredicate(ParseState *pstate, JsonIsPredicate *pred)
static Node * transformJsonObjectAgg(ParseState *pstate, JsonObjectAgg *agg)
static Node * transformAExprDistinct(ParseState *pstate, A_Expr *a)
Node * ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs, Node *last_srf, FuncCall *fn, bool proc_call, int location)
void free_parsestate(ParseState *pstate)
int parser_errposition(ParseState *pstate, int location)
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
Const * make_const(ParseState *pstate, A_Const *aconst)
ParseState * make_parsestate(ParseState *parentParseState)
@ EXPR_KIND_EXECUTE_PARAMETER
@ EXPR_KIND_COLUMN_DEFAULT
@ EXPR_KIND_STATS_EXPRESSION
@ EXPR_KIND_INDEX_EXPRESSION
@ EXPR_KIND_MERGE_RETURNING
@ EXPR_KIND_PARTITION_BOUND
@ EXPR_KIND_FUNCTION_DEFAULT
@ EXPR_KIND_WINDOW_FRAME_RANGE
@ EXPR_KIND_FROM_SUBSELECT
@ EXPR_KIND_WINDOW_FRAME_GROUPS
@ EXPR_KIND_PARTITION_EXPRESSION
@ EXPR_KIND_INDEX_PREDICATE
@ EXPR_KIND_INSERT_TARGET
@ EXPR_KIND_ALTER_COL_TRANSFORM
@ EXPR_KIND_UPDATE_TARGET
@ EXPR_KIND_SELECT_TARGET
@ EXPR_KIND_GENERATED_COLUMN
@ EXPR_KIND_CALL_ARGUMENT
@ EXPR_KIND_FROM_FUNCTION
@ EXPR_KIND_UPDATE_SOURCE
@ EXPR_KIND_CHECK_CONSTRAINT
@ EXPR_KIND_WINDOW_PARTITION
@ EXPR_KIND_WINDOW_FRAME_ROWS
@ EXPR_KIND_VALUES_SINGLE
Expr * make_op(ParseState *pstate, List *opname, Node *ltree, Node *rtree, Node *last_srf, int location)
Expr * make_scalar_array_op(ParseState *pstate, List *opname, bool useOr, Node *ltree, Node *rtree, int location)
void markNullableIfNeeded(ParseState *pstate, Var *var)
void errorMissingColumn(ParseState *pstate, const char *relname, const char *colname, int location)
Node * colNameToVar(ParseState *pstate, const char *colname, bool localonly, int location)
void markVarForSelectPriv(ParseState *pstate, Var *var)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
Node * scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, const char *colname, int location)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
char * FigureColname(Node *node)
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
#define ISCOMPLEX(typeid)
Query * parse_sub_analyze(Node *parseTree, ParseState *parentParseState, CommonTableExpr *parentCTE, bool locked_from_parent, bool resolve_unknowns)
Query * transformStmt(ParseState *pstate, Node *parseTree)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
static void * list_nth(const List *list, int n)
#define list_make2(x1, x2)
static Datum BoolGetDatum(bool X)
static Datum NameGetDatum(const NameData *X)
static Datum CStringGetDatum(const char *X)
@ SVFOP_CURRENT_TIMESTAMP
@ SVFOP_CURRENT_TIMESTAMP_N
@ JSON_BEHAVIOR_EMPTY_OBJECT
@ JSON_BEHAVIOR_EMPTY_ARRAY
static int cmp(const chr *x, const chr *y, size_t len)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
static chr element(struct vars *v, const chr *startp, const chr *endp)
void check_stack_depth(void)
JsonAggConstructor * constructor
JsonReturning * returning
JsonReturning * returning
JsonValueExpr * context_item
JsonAggConstructor * constructor
JsonReturning * returning
NullTestType nulltesttype
ParseState * parentParseState
ParseNamespaceItem * p_target_nsitem
ParseExprKind p_expr_kind
List * p_multiassign_exprs
ParseParamRefHook p_paramref_hook
PreParseColumnRefHook p_pre_columnref_hook
PostParseColumnRefHook p_post_columnref_hook
static void * fn(void *arg)
int count_nonjunk_tlist_entries(List *tlist)
bool DomainHasConstraints(Oid type_id)
String * makeString(char *str)
bool contain_vars_of_level(Node *node, int levelsup)
bool contain_var_clause(Node *node)
#define select(n, r, w, e, timeout)
char * map_sql_identifier_to_xml_name(const char *ident, bool fully_escaped, bool escape_period)