39 #include "utils/fmgroids.h"
78 int sublevels_up,
int location);
98 List **passing_values,
List **passing_names);
104 List *largs,
List *rargs,
int location);
162 case T_A_Indirection:
175 case T_CollateClause:
217 elog(
ERROR,
"unrecognized A_Expr kind: %d",
a->kind);
232 case T_MultiAssignRef:
240 case T_MergeSupportFunc:
274 case T_SQLValueFunction:
302 case T_CurrentOfExpr:
312 (
errcode(ERRCODE_SYNTAX_ERROR),
313 errmsg(
"DEFAULT is not allowed in this context"),
331 result = (
Node *) expr;
335 case T_JsonObjectConstructor:
339 case T_JsonArrayConstructor:
343 case T_JsonArrayQueryConstructor:
347 case T_JsonObjectAgg:
355 case T_JsonIsPredicate:
359 case T_JsonParseExpr:
363 case T_JsonScalarExpr:
367 case T_JsonSerializeExpr:
402 ((
Var *) relref)->varno,
403 ((
Var *) relref)->varlevelsup);
405 (
errcode(ERRCODE_UNDEFINED_COLUMN),
406 errmsg(
"column %s.%s does not exist",
407 rte->eref->aliasname,
attname),
417 (
errcode(ERRCODE_UNDEFINED_COLUMN),
418 errmsg(
"column \"%s\" not found in data type %s",
421 else if (relTypeId == RECORDOID)
423 (
errcode(ERRCODE_UNDEFINED_COLUMN),
424 errmsg(
"could not identify column \"%s\" in record data type",
429 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
430 errmsg(
"column notation .%s applied to type %s, "
431 "which is not a composite type",
451 foreach(
i,
ind->indirection)
456 subscripts =
lappend(subscripts, n);
460 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
461 errmsg(
"row expansion via \"*\" is not supported here"),
487 if (newresult == NULL)
513 char *nspname = NULL;
515 char *colname = NULL;
524 } crerr = CRERR_NO_COLUMN;
584 err =
_(
"cannot use column reference in DEFAULT expression");
587 err =
_(
"cannot use column reference in partition bound expression");
600 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
684 crerr = CRERR_NO_RTE;
731 crerr = CRERR_NO_RTE;
780 crerr = CRERR_WRONG_DB;
790 crerr = CRERR_NO_RTE;
823 crerr = CRERR_TOO_MANY;
843 else if (hookresult != NULL)
845 (
errcode(ERRCODE_AMBIGUOUS_COLUMN),
846 errmsg(
"column reference \"%s\" is ambiguous",
858 case CRERR_NO_COLUMN:
867 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
868 errmsg(
"cross-database references are not implemented: %s",
874 (
errcode(ERRCODE_SYNTAX_ERROR),
875 errmsg(
"improper qualified name (too many dotted names): %s",
901 (
errcode(ERRCODE_UNDEFINED_PARAMETER),
925 Node *lexpr =
a->lexpr;
926 Node *rexpr =
a->rexpr;
967 s->operName =
a->name;
1034 Node *lexpr =
a->lexpr;
1035 Node *rexpr =
a->rexpr;
1099 if (result->opresulttype != BOOLOID)
1101 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1102 errmsg(
"NULLIF requires = operator to yield boolean"),
1104 if (result->opretset)
1106 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1108 errmsg(
"%s must not return a set",
"NULLIF"),
1121 return (
Node *) result;
1127 Node *result = NULL;
1155 rexprs = rvars = rnonvars =
NIL;
1156 foreach(l, (
List *)
a->rexpr)
1160 rexprs =
lappend(rexprs, rexpr);
1162 rvars =
lappend(rvars, rexpr);
1164 rnonvars =
lappend(rnonvars, rexpr);
1198 if (
OidIsValid(scalar_type) && scalar_type != RECORDOID)
1212 foreach(l, rnonvars)
1219 aexprs =
lappend(aexprs, rexpr);
1222 newa->array_typeid = array_type;
1224 newa->element_typeid = scalar_type;
1226 newa->multidims =
false;
1368 elog(
ERROR,
"unrecognized A_Expr kind: %d",
a->kind);
1387 while (parent_pstate &&
1393 errcode(ERRCODE_SYNTAX_ERROR),
1394 errmsg(
"MERGE_ACTION() can only be used in the RETURNING list of a MERGE command"),
1420 elog(
ERROR,
"unrecognized boolop: %d", (
int)
a->boolop);
1425 foreach(lc,
a->args)
1460 if (
fn->agg_within_group)
1463 foreach(
args,
fn->agg_order)
1494 if (maref->
colno == 1)
1517 (
errcode(ERRCODE_SYNTAX_ERROR),
1518 errmsg(
"number of columns does not match number of values"),
1549 (
errcode(ERRCODE_SYNTAX_ERROR),
1550 errmsg(
"number of columns does not match number of values"),
1563 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1564 errmsg(
"source for a multiple-column UPDATE item must be a sub-SELECT or ROW() expression"),
1601 return (
Node *) param;
1626 elog(
ERROR,
"unexpected expr type in multiassign list");
1691 (
Node *) placeholder,
1705 newargs =
lappend(newargs, neww);
1709 newc->
args = newargs;
1712 defresult = (
Node *)
c->defresult;
1713 if (defresult == NULL)
1719 defresult = (
Node *) n;
1732 newc->casetype = ptype;
1743 foreach(l, newc->
args)
1757 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1759 errmsg(
"set-returning functions are not allowed in %s",
1761 errhint(
"You might be able to move the set-returning function into a LATERAL FROM item."),
1767 return (
Node *) newc;
1823 err =
_(
"cannot use subquery in check constraint");
1827 err =
_(
"cannot use subquery in DEFAULT expression");
1830 err =
_(
"cannot use subquery in index expression");
1833 err =
_(
"cannot use subquery in index predicate");
1836 err =
_(
"cannot use subquery in statistics expression");
1839 err =
_(
"cannot use subquery in transform expression");
1842 err =
_(
"cannot use subquery in EXECUTE parameter");
1845 err =
_(
"cannot use subquery in trigger WHEN condition");
1848 err =
_(
"cannot use subquery in partition bound");
1851 err =
_(
"cannot use subquery in partition key expression");
1854 err =
_(
"cannot use subquery in CALL argument");
1857 err =
_(
"cannot use subquery in COPY FROM WHERE condition");
1860 err =
_(
"cannot use subquery in column generation expression");
1873 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1890 elog(
ERROR,
"unexpected non-SELECT command in SubLink");
1901 sublink->operName =
NIL;
1912 (
errcode(ERRCODE_SYNTAX_ERROR),
1913 errmsg(
"subquery must return only one column"),
1921 sublink->operName =
NIL;
1927 sublink->operName =
NIL;
1940 if (sublink->operName ==
NIL)
1948 left_list = ((
RowExpr *) lefthand)->args;
1973 right_list =
lappend(right_list, param);
1983 (
errcode(ERRCODE_SYNTAX_ERROR),
1984 errmsg(
"subquery has too many columns"),
1988 (
errcode(ERRCODE_SYNTAX_ERROR),
1989 errmsg(
"subquery has too few columns"),
2030 newa->multidims =
false;
2049 newa->multidims =
true;
2060 newa->multidims =
true;
2063 newelems =
lappend(newelems, newe);
2076 coerce_type = (newa->multidims ? array_type : element_type);
2082 if (newelems ==
NIL)
2084 (
errcode(ERRCODE_INDETERMINATE_DATATYPE),
2085 errmsg(
"cannot determine type of empty array"),
2086 errhint(
"Explicitly cast to the desired type, "
2087 "for example ARRAY[]::integer[]."),
2093 if (newa->multidims)
2099 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2100 errmsg(
"could not find element type for data type %s",
2110 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2111 errmsg(
"could not find array type for data type %s",
2115 coerce_hard =
false;
2144 (
errcode(ERRCODE_CANNOT_COERCE),
2145 errmsg(
"cannot cast type %s to %s",
2154 newcoercedelems =
lappend(newcoercedelems, newe);
2157 newa->array_typeid = array_type;
2159 newa->element_typeid = element_type;
2163 return (
Node *) newa;
2182 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
2183 errmsg(
"ROW expressions can have at most %d entries",
2188 newr->row_typeid = RECORDOID;
2192 newr->colnames =
NIL;
2195 snprintf(fname,
sizeof(fname),
"f%d", fnum);
2201 return (
Node *) newr;
2213 foreach(
args,
c->args)
2219 newargs =
lappend(newargs, newe);
2226 foreach(
args, newargs)
2234 newcoercedargs =
lappend(newcoercedargs, newe);
2240 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2242 errmsg(
"set-returning functions are not allowed in %s",
2244 errhint(
"You might be able to move the set-returning function into a LATERAL FROM item."),
2248 newc->
args = newcoercedargs;
2250 return (
Node *) newc;
2269 newargs =
lappend(newargs, newe);
2276 foreach(
args, newargs)
2284 newcoercedargs =
lappend(newcoercedargs, newe);
2287 newm->
args = newcoercedargs;
2289 return (
Node *) newm;
2302 svf->type = DATEOID;
2305 svf->type = TIMETZOID;
2308 svf->type = TIMETZOID;
2312 svf->type = TIMESTAMPTZOID;
2315 svf->type = TIMESTAMPTZOID;
2319 svf->type = TIMEOID;
2322 svf->type = TIMEOID;
2326 svf->type = TIMESTAMPOID;
2329 svf->type = TIMESTAMPOID;
2338 svf->type = NAMEOID;
2342 return (
Node *) svf;
2358 newx->xmloption =
x->xmloption;
2359 newx->type = XMLOID;
2368 newx->arg_names =
NIL;
2370 foreach(lc,
x->named_args)
2386 (
errcode(ERRCODE_SYNTAX_ERROR),
2388 ?
errmsg(
"unnamed XML attribute value must be a column reference")
2389 :
errmsg(
"unnamed XML element value must be a column reference"),
2399 foreach(lc2, newx->arg_names)
2403 (
errcode(ERRCODE_SYNTAX_ERROR),
2404 errmsg(
"XML attribute name \"%s\" appears more than once",
2417 foreach(lc,
x->args)
2471 return (
Node *) newx;
2495 xexpr->type = targetType;
2496 xexpr->typmod = targetTypmod;
2505 TEXTOID, targetType, targetTypmod,
2511 (
errcode(ERRCODE_CANNOT_COERCE),
2512 errmsg(
"cannot cast XMLSERIALIZE result to %s",
2521 const char *clausename;
2523 switch (
b->booltesttype)
2526 clausename =
"IS TRUE";
2529 clausename =
"IS NOT TRUE";
2532 clausename =
"IS FALSE";
2535 clausename =
"IS NOT FALSE";
2538 clausename =
"IS UNKNOWN";
2541 clausename =
"IS NOT UNKNOWN";
2544 elog(
ERROR,
"unrecognized booltesttype: %d",
2545 (
int)
b->booltesttype);
2590 if (node != NULL &&
IsA(node,
Param))
2604 return (
Node *) cexpr;
2612 int sublevels_up,
int location)
2635 sublevels_up,
true);
2646 return (
Node *) result;
2660 sublevels_up, location,
false,
2665 rowexpr->row_typeid = RECORDOID;
2672 return (
Node *) rowexpr;
2706 int32 targetBaseTypmod;
2715 targetBaseTypmod = targetTypmod;
2746 targetType, targetTypmod,
2752 (
errcode(ERRCODE_CANNOT_COERCE),
2753 errmsg(
"cannot cast type %s to %s",
2783 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2784 errmsg(
"collations are not supported by type %s",
2791 return (
Node *) newc;
2808 List *largs,
List *rargs,
int location)
2817 List **opinfo_lists;
2825 (
errcode(ERRCODE_SYNTAX_ERROR),
2826 errmsg(
"unequal number of entries in row expressions"),
2835 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2836 errmsg(
"cannot compare rows of zero length"),
2858 if (
cmp->opresulttype != BOOLOID)
2860 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2861 errmsg(
"row comparison operator must yield type boolean, "
2867 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2868 errmsg(
"row comparison operator must not return a set"),
2903 foreach(
j, opinfo_lists[
i])
2910 strats = this_strats;
2926 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2927 errmsg(
"could not determine interpretation of row comparison operator %s",
2929 errhint(
"Row comparison operators must be associated with btree operator families."),
2948 for (
i = 0;
i < nopers;
i++)
2953 foreach(
j, opinfo_lists[
i])
2967 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2968 errmsg(
"could not determine interpretation of row comparison operator %s",
2970 errdetail(
"There are multiple equally-plausible candidates."),
2994 rcexpr->opnos = opnos;
2995 rcexpr->opfamilies = opfamilies;
2996 rcexpr->inputcollids =
NIL;
2997 rcexpr->
largs = largs;
2998 rcexpr->
rargs = rargs;
3000 return (
Node *) rcexpr;
3013 Node *result = NULL;
3021 (
errcode(ERRCODE_SYNTAX_ERROR),
3022 errmsg(
"unequal number of entries in row expressions"),
3060 if (((
OpExpr *) result)->opresulttype != BOOLOID)
3062 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3063 errmsg(
"IS DISTINCT FROM requires = operator to yield boolean"),
3065 if (((
OpExpr *) result)->opretset)
3067 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3069 errmsg(
"%s must not return a set",
"IS DISTINCT FROM"),
3097 nt->argisrow =
false;
3115 return "invalid expression context";
3117 return "extension expression";
3121 return "JOIN/USING";
3123 return "sub-SELECT in FROM";
3125 return "function in FROM";
3135 return "window PARTITION BY";
3137 return "window ORDER BY";
3139 return "window RANGE";
3141 return "window ROWS";
3143 return "window GROUPS";
3152 return "MERGE WHEN";
3158 return "DISTINCT ON";
3176 return "index expression";
3178 return "index predicate";
3180 return "statistics expression";
3188 return "partition bound";
3190 return "PARTITION BY";
3196 return "GENERATED AS";
3207 return "unrecognized expression kind";
3265 return (
Node *) fexpr;
3279 Oid targettype,
bool isarg)
3287 bool typispreferred;
3302 errcode(ERRCODE_DATATYPE_MISMATCH),
3303 errmsg(
"JSON ENCODING clause is only allowed for bytea input type"),
3306 if (exprtype == JSONOID || exprtype == JSONBOID)
3334 case TIMESTAMPTZOID:
3338 if (typcategory == TYPCATEGORY_STRING)
3346 else if (exprtype == JSONOID || exprtype == JSONBOID)
3352 (
OidIsValid(targettype) && exprtype != targettype))
3355 bool only_allow_cast =
OidIsValid(targettype);
3363 exprtype != BYTEAOID && typcategory != TYPCATEGORY_STRING)
3365 errcode(ERRCODE_DATATYPE_MISMATCH),
3367 errmsg(
"cannot use non-string types with implicit FORMAT JSON clause") :
3368 errmsg(
"cannot use non-string types with explicit FORMAT JSON clause"),
3399 if (only_allow_cast)
3401 (
errcode(ERRCODE_CANNOT_COERCE),
3402 errmsg(
"cannot cast type %s to %s",
3407 fnoid = targettype == JSONOID ? F_TO_JSON : F_TO_JSONB;
3413 coerced = (
Node *) fexpr;
3416 if (coerced == expr)
3440 Oid targettype,
bool allow_format_for_non_strings)
3442 if (!allow_format_for_non_strings &&
3444 (targettype != BYTEAOID &&
3445 targettype != JSONOID &&
3446 targettype != JSONBOID))
3449 bool typispreferred;
3453 if (typcategory != TYPCATEGORY_STRING)
3455 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3457 errmsg(
"cannot use JSON format with non-string output types"));
3465 if (targettype != BYTEAOID &&
3468 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3470 errmsg(
"cannot set JSON encoding for non-bytea output types"));
3474 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3475 errmsg(
"unsupported JSON encoding"),
3476 errhint(
"Only UTF8 JSON encoding is supported."),
3510 if (
output->typeName->setof)
3512 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3513 errmsg(
"returning SETOF types is not supported in SQL/JSON functions"));
3517 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3518 errmsg(
"returning pseudo-types is not supported in SQL/JSON functions"));
3544 bool have_jsonb =
false;
3551 have_jsonb |= typid == JSONBOID;
3559 returning->
typid = JSONBOID;
3565 returning->
typid = JSONOID;
3597 returning->
typid == BYTEAOID)
3610 return (
Node *) fexpr;
3628 if (!
res && report_error)
3630 errcode(ERRCODE_CANNOT_COERCE),
3631 errmsg(
"cannot cast type %s to %s",
3645 bool unique,
bool absent_on_null,
int location)
3652 jsctor->
func = fexpr;
3673 placeholder = (
Node *) cte;
3684 placeholder = (
Node *) cte;
3689 if (coercion != placeholder)
3692 return (
Node *) jsctor;
3714 foreach(lc, ctor->
exprs)
3760 errcode(ERRCODE_SYNTAX_ERROR),
3761 errmsg(
"subquery must return only one column"),
3782 target->
name = NULL;
3790 range->lateral =
false;
3792 range->alias = alias;
3800 sublink->operName =
NIL;
3813 Oid aggfnoid,
Oid aggtype,
3815 bool unique,
bool absent_on_null)
3830 wfunc->wintype = aggtype;
3834 wfunc->runCondition =
NIL;
3836 wfunc->winstar =
false;
3837 wfunc->winagg =
true;
3845 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3846 errmsg(
"aggregate ORDER BY is not implemented for window functions"),
3852 node = (
Node *) wfunc;
3859 aggref->aggtype = aggtype;
3867 aggref->aggstar =
false;
3868 aggref->aggvariadic =
false;
3869 aggref->aggkind = AGGKIND_NORMAL;
3870 aggref->aggpresorted =
false;
3874 aggref->aggtransno = -1;
3879 node = (
Node *) aggref;
3883 returning, unique, absent_on_null,
3920 aggfnoid = F_JSONB_OBJECT_AGG_UNIQUE_STRICT;
3922 aggfnoid = F_JSONB_OBJECT_AGG_STRICT;
3924 aggfnoid = F_JSONB_OBJECT_AGG_UNIQUE;
3926 aggfnoid = F_JSONB_OBJECT_AGG;
3934 aggfnoid = F_JSON_OBJECT_AGG_UNIQUE_STRICT;
3936 aggfnoid = F_JSON_OBJECT_AGG_STRICT;
3938 aggfnoid = F_JSON_OBJECT_AGG_UNIQUE;
3940 aggfnoid = F_JSON_OBJECT_AGG;
3946 args, aggfnoid, aggtype,
3976 aggfnoid = agg->
absent_on_null ? F_JSONB_AGG_STRICT : F_JSONB_AGG;
4010 foreach(lc, ctor->
exprs)
4033 Node *expr = raw_expr;
4038 if (*exprtype == BYTEAOID)
4044 *exprtype = TEXTOID;
4047 expr = (
Node *) jve;
4052 bool typispreferred;
4056 if (*exprtype == UNKNOWNOID || typcategory == TYPCATEGORY_STRING)
4062 *exprtype = TEXTOID;
4067 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4069 errmsg(
"cannot use JSON FORMAT ENCODING clause for non-bytea input types")));
4086 if (exprtype != TEXTOID && exprtype != JSONOID && exprtype != JSONBOID)
4088 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4089 errmsg(
"cannot use type %s in IS JSON predicate",
4112 if (returning->
typid != JSONOID && returning->
typid != JSONBOID)
4114 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4115 errmsg(
"cannot use RETURNING type %s in %s",
4122 Oid targettype = JSONOID;
4127 returning->
typid = targettype;
4161 if (arg_type != TEXTOID)
4163 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4164 errmsg(
"cannot use non-string types with WITH UNIQUE KEYS clause"),
4202 returning,
false,
false, jsexpr->
location);
4225 if (returning->
typid != BYTEAOID)
4228 bool typispreferred;
4232 if (typcategory != TYPCATEGORY_STRING)
4234 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4235 errmsg(
"cannot use RETURNING type %s in %s",
4237 "JSON_SERIALIZE()"),
4238 errhint(
"Try returning a string type or bytea.")));
4246 returning->
typid = TEXTOID;
4251 NULL, returning,
false,
false, expr->
location);
4263 const char *func_name = NULL;
4269 func_name =
"JSON_EXISTS";
4273 func_name =
"JSON_QUERY";
4277 func_name =
"JSON_VALUE";
4281 func_name =
"JSON_TABLE";
4285 elog(
ERROR,
"invalid JsonFuncExpr op %d", (
int) func->
op);
4302 errcode(ERRCODE_SYNTAX_ERROR),
4303 errmsg(
"cannot specify FORMAT JSON in RETURNING clause of %s()",
4315 errcode(ERRCODE_SYNTAX_ERROR),
4316 errmsg(
"SQL/JSON QUOTES behavior must not be specified when WITH WRAPPER is used"),
4328 errcode(ERRCODE_SYNTAX_ERROR),
4329 errmsg(
"invalid ON EMPTY behavior"),
4330 errdetail(
"Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON EMPTY for JSON_QUERY()."),
4334 errcode(ERRCODE_SYNTAX_ERROR),
4335 errmsg(
"invalid ON EMPTY behavior for column \"%s\"",
4337 errdetail(
"Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON EMPTY for formatted columns."),
4350 errcode(ERRCODE_SYNTAX_ERROR),
4351 errmsg(
"invalid ON ERROR behavior"),
4352 errdetail(
"Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for JSON_QUERY()."),
4356 errcode(ERRCODE_SYNTAX_ERROR),
4357 errmsg(
"invalid ON ERROR behavior for column \"%s\"",
4359 errdetail(
"Only ERROR, NULL, EMPTY [ ARRAY ], EMPTY OBJECT, or DEFAULT expression is allowed in ON ERROR for formatted columns."),
4374 errcode(ERRCODE_SYNTAX_ERROR),
4375 errmsg(
"invalid ON ERROR behavior"),
4376 errdetail(
"Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in ON ERROR for JSON_EXISTS()."),
4380 errcode(ERRCODE_SYNTAX_ERROR),
4381 errmsg(
"invalid ON ERROR behavior for column \"%s\"",
4383 errdetail(
"Only ERROR, TRUE, FALSE, or UNKNOWN is allowed in ON ERROR for EXISTS columns."),
4395 errcode(ERRCODE_SYNTAX_ERROR),
4396 errmsg(
"invalid ON EMPTY behavior"),
4397 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in ON EMPTY for JSON_VALUE()."),
4401 errcode(ERRCODE_SYNTAX_ERROR),
4402 errmsg(
"invalid ON EMPTY behavior for column \"%s\"",
4404 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in ON EMPTY for scalar columns."),
4414 errcode(ERRCODE_SYNTAX_ERROR),
4415 errmsg(
"invalid ON ERROR behavior"),
4416 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in ON ERROR for JSON_VALUE()."),
4420 errcode(ERRCODE_SYNTAX_ERROR),
4421 errmsg(
"invalid ON ERROR behavior for column \"%s\"",
4423 errdetail(
"Only ERROR, NULL, or DEFAULT expression is allowed in ON ERROR for scalar columns."),
4430 jsexpr->
op = func->
op;
4449 if (path_spec == NULL)
4451 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4452 errmsg(
"JSON path expression must be of type %s, not of type %s",
4492 ret->
typid = JSONBOID;
4581 elog(
ERROR,
"invalid JsonFuncExpr op %d", (
int) func->
op);
4585 return (
Node *) jsexpr;
4594 List **passing_values,
List **passing_names)
4598 *passing_values =
NIL;
4599 *passing_names =
NIL;
4608 *passing_values =
lappend(*passing_values, expr);
4633 case T_CoerceToDomain:
4634 case T_ArrayCoerceExpr:
4635 case T_ConvertRowtypeExpr:
4657 bool coerce_at_runtime =
false;
4662 btype = behavior->
btype;
4669 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4670 errmsg(
"can only specify a constant, non-aggregate function, or operator expression for DEFAULT"),
4674 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4675 errmsg(
"DEFAULT expression must not contain column references"),
4679 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4680 errmsg(
"DEFAULT expression must not return a set"),
4690 Node *coerced_expr = expr;
4691 bool isnull = (
IsA(expr,
Const) && ((
Const *) expr)->constisnull);
4702 btype == default_behavior))
4703 coerce_at_runtime =
true;
4716 returning->
typid, baseTypmod,
4724 if (coerced_expr == NULL)
4726 errcode(ERRCODE_CANNOT_COERCE),
4727 errmsg(
"cannot cast behavior expression of type %s to %s",
4732 expr = coerced_expr;
4736 behavior->
expr = expr;
4740 behavior->
coerce = coerce_at_runtime;
4753 Oid typid = JSONBOID;
4755 bool isbyval =
false;
4756 bool isnull =
false;
4800 elog(
ERROR,
"unrecognized SQL/JSON behavior %d", btype);
4805 con->location = location;
4807 return (
Node *) con;
#define InvalidAttrNumber
int32 anytimestamp_typmod_check(bool istz, int32 typmod)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
#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 * list_truncate(List *list, int new_size)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
List * lcons(void *datum, List *list)
List * list_delete_last(List *list)
Oid get_element_type(Oid typid)
bool type_is_rowtype(Oid typid)
List * get_op_btree_interpretation(Oid opno)
bool type_is_collatable(Oid typid)
char get_typtype(Oid typid)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid get_array_type(Oid typid)
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
#define type_is_array(typid)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
JsonBehavior * makeJsonBehavior(JsonBehaviorType btype, Node *expr, int location)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
JsonFormat * makeJsonFormat(JsonFormatType type, JsonEncoding encoding, int location)
Expr * makeBoolExpr(BoolExprType boolop, List *args, int location)
Node * makeBoolConst(bool value, bool isnull)
JsonValueExpr * makeJsonValueExpr(Expr *raw_expr, Expr *formatted_expr, JsonFormat *format)
Node * makeJsonIsPredicate(Node *expr, JsonFormat *format, JsonValueType item_type, bool unique_keys, int location)
A_Expr * makeSimpleA_Expr(A_Expr_Kind kind, char *name, Node *lexpr, Node *rexpr, 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)
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
bool verify_common_type(Oid common_type, List *exprs)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)
int parser_coercion_errposition(ParseState *pstate, int coerce_location, Node *input_expr)
Node * coerce_to_specific_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
void assign_expr_collations(ParseState *pstate, Node *expr)
static Node * transformMergeSupportFunc(ParseState *pstate, MergeSupportFunc *f)
static JsonReturning * transformJsonOutput(ParseState *pstate, const JsonOutput *output, bool allow_format)
static Node * make_nulltest_from_distinct(ParseState *pstate, A_Expr *distincta, Node *arg)
static Node * transformJsonValueExpr(ParseState *pstate, const char *constructName, JsonValueExpr *ve, JsonFormatType default_format, Oid targettype, bool isarg)
static void unknown_attribute(ParseState *pstate, Node *relref, const char *attname, int location)
static Node * makeJsonByteaToTextConversion(Node *expr, JsonFormat *format, int location)
static Node * transformJsonArrayConstructor(ParseState *pstate, JsonArrayConstructor *ctor)
static Node * transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr)
static Node * transformAExprOpAll(ParseState *pstate, A_Expr *a)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
static Node * transformJsonParseExpr(ParseState *pstate, JsonParseExpr *jsexpr)
static Node * transformAExprIn(ParseState *pstate, A_Expr *a)
static JsonReturning * transformJsonConstructorOutput(ParseState *pstate, JsonOutput *output, List *args)
static void checkJsonOutputFormat(ParseState *pstate, const JsonFormat *format, Oid targettype, bool allow_format_for_non_strings)
static Node * transformAExprOpAny(ParseState *pstate, A_Expr *a)
static Node * transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
static Node * transformExprRecurse(ParseState *pstate, Node *expr)
static JsonReturning * transformJsonReturning(ParseState *pstate, JsonOutput *output, const char *fname)
static Node * transformAExprNullIf(ParseState *pstate, A_Expr *a)
static Node * transformJsonScalarExpr(ParseState *pstate, JsonScalarExpr *jsexpr)
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 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 Node * makeJsonConstructorExpr(ParseState *pstate, JsonConstructorType type, List *args, Expr *fexpr, JsonReturning *returning, bool unique, bool absent_on_null, int location)
static Node * transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
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 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 * coerceJsonFuncExpr(ParseState *pstate, Node *expr, const JsonReturning *returning, bool report_error)
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 * transformParamRef(ParseState *pstate, ParamRef *pref)
static Node * transformCaseExpr(ParseState *pstate, CaseExpr *c)
static Node * transformIndirection(ParseState *pstate, A_Indirection *ind)
const char * ParseExprKindName(ParseExprKind exprKind)
static Node * transformJsonParseArg(ParseState *pstate, Node *jsexpr, JsonFormat *format, Oid *exprtype)
static Node * transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr)
static Node * transformRowExpr(ParseState *pstate, RowExpr *r, bool allowDefault)
static Node * transformXmlExpr(ParseState *pstate, XmlExpr *x)
static Node * transformAExprBetween(ParseState *pstate, A_Expr *a)
static Node * transformWholeRowRef(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location)
static Const * getJsonEncodingConst(JsonFormat *format)
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)
SubscriptingRef * transformContainerSubscripts(ParseState *pstate, Node *containerBase, Oid containerType, int32 containerTypMod, List *indirection, bool isAssignment)
int parser_errposition(ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
Const * make_const(ParseState *pstate, A_Const *aconst)
@ 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)
RangeTblEntry * GetRTEByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
void errorMissingColumn(ParseState *pstate, const char *relname, const char *colname, int location)
void markVarForSelectPriv(ParseState *pstate, Var *var)
void errorMissingRTE(ParseState *pstate, RangeVar *relation)
Node * scanNSItemForColumn(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, const char *colname, int location)
ParseNamespaceItem * refnameNamespaceItem(ParseState *pstate, const char *schemaname, const char *refname, int location, int *sublevels_up)
Node * colNameToVar(ParseState *pstate, const char *colname, bool localonly, int location)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
List * transformExpressionList(ParseState *pstate, List *exprlist, ParseExprKind exprKind, bool allowDefault)
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)
void check_stack_depth(void)
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 struct cvec * range(struct vars *v, chr a, chr b, int cases)
static int cmp(const chr *x, const chr *y, size_t len)
static chr element(struct vars *v, const chr *startp, const chr *endp)
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)