29 #include "utils/fmgroids.h"
36 Oid targetTypeId,
int32 targetTypMod,
39 bool hideInputCoercion);
44 Oid targetTypeId,
int32 targetTypMod,
105 targettype, targettypmod,
106 ccontext, cformat, location);
114 targettype, targettypmod,
115 ccontext, cformat, location,
116 (result != expr && !
IsA(result,
Const)));
124 newcoll->
arg = (
Expr *) result;
127 result = (
Node *) newcoll;
158 Oid inputTypeId,
Oid targetTypeId,
int32 targetTypeMod,
165 if (targetTypeId == inputTypeId ||
171 if (targetTypeId == ANYOID ||
172 targetTypeId == ANYELEMENTOID ||
173 targetTypeId == ANYNONARRAYOID ||
174 targetTypeId == ANYCOMPATIBLEOID ||
175 targetTypeId == ANYCOMPATIBLENONARRAYOID)
191 if (targetTypeId == ANYARRAYOID ||
192 targetTypeId == ANYENUMOID ||
193 targetTypeId == ANYRANGEOID ||
194 targetTypeId == ANYMULTIRANGEOID ||
195 targetTypeId == ANYCOMPATIBLEARRAYOID ||
196 targetTypeId == ANYCOMPATIBLERANGEOID ||
197 targetTypeId == ANYCOMPATIBLEMULTIRANGEOID)
214 if (inputTypeId != UNKNOWNOID)
218 if (baseTypeId != inputTypeId)
232 if (inputTypeId == UNKNOWNOID &&
IsA(node,
Const))
267 baseTypeMod = targetTypeMod;
279 if (baseTypeId == INTERVALOID)
280 inputTypeMod = baseTypeMod;
287 newcon->consttypmod = inputTypeMod;
289 newcon->constlen =
typeLen(baseType);
290 newcon->constbyval =
typeByVal(baseType);
291 newcon->constisnull = con->constisnull;
298 newcon->location = con->location;
310 if (!con->constisnull)
324 if (!con->constisnull && newcon->constlen == -1)
328 #ifdef RANDOMIZE_ALLOCATED_MEMORY
341 if (!con->constisnull && !newcon->constbyval)
348 if (newcon->constlen == -1)
350 if (!
datumIsEqual(newcon->constvalue, val2,
false, newcon->constlen))
351 elog(
WARNING,
"type %s has unstable input conversion for \"%s\"",
358 result = (
Node *) newcon;
361 if (baseTypeId != targetTypeId)
363 baseTypeId, baseTypeMod,
365 ccontext, cformat, location,
400 inputTypeId, targetTypeId, targetTypeMod,
401 ccontext, cformat, location);
406 newcoll->
arg = (
Expr *) result;
409 result = (
Node *) newcoll;
429 baseTypeMod = targetTypeMod;
433 baseTypeId, baseTypeMod,
434 ccontext, cformat, location);
440 if (targetTypeId != baseTypeId)
443 ccontext, cformat, location,
458 ccontext, cformat, location,
479 if (inputTypeId == RECORDOID &&
484 ccontext, cformat, location);
486 if (targetTypeId == RECORDOID &&
494 if (inputTypeId == RECORDARRAYOID &&
501 if (targetTypeId == RECORDARRAYOID &&
525 if (baseTypeId != inputTypeId)
537 r->convertformat = cformat;
542 elog(
ERROR,
"failed to find conversion function from %s to %s",
559 bool have_generics =
false;
563 for (
i = 0;
i < nargs;
i++)
565 Oid inputTypeId = input_typeids[
i];
566 Oid targetTypeId = target_typeids[
i];
571 if (inputTypeId == targetTypeId)
575 if (targetTypeId == ANYOID)
579 if (IsPolymorphicType(targetTypeId))
581 have_generics =
true;
589 if (inputTypeId == UNKNOWNOID)
605 if (inputTypeId == RECORDOID &&
612 if (targetTypeId == RECORDOID &&
622 if (inputTypeId == RECORDARRAYOID &&
630 if (targetTypeId == RECORDARRAYOID &&
678 bool hideInputCoercion)
687 if (baseTypeId == typeId)
691 if (hideInputCoercion)
719 result->resulttypmod = -1;
721 result->coercionformat = cformat;
724 return (
Node *) result;
756 bool hideInputCoercion)
766 if (hideInputCoercion)
774 if (targetTypMod < 0)
782 targetTypeId, targetTypMod,
783 ccontext, cformat, location);
794 cformat, location,
false);
842 Oid targetTypeId,
int32 targetTypMod,
855 elog(
ERROR,
"cache lookup failed for function %u", funcId);
865 Assert(!procstruct->proretset);
866 Assert(procstruct->prokind == PROKIND_FUNCTION);
867 nargs = procstruct->pronargs;
868 Assert(nargs >= 1 && nargs <= 3);
870 Assert(nargs < 2 || procstruct->proargtypes.values[1] == INT4OID);
871 Assert(nargs < 3 || procstruct->proargtypes.values[2] == BOOLOID);
918 return (
Node *) fexpr;
925 Oid sourceBaseTypeId;
926 int32 sourceBaseTypeMod;
927 Oid targetElementType;
947 ctest->typeMod = sourceBaseTypeMod;
962 if (elemexpr == NULL)
963 elog(
ERROR,
"failed to coerce array element type as expected");
975 acoerce->coerceformat = cformat;
978 return (
Node *) acoerce;
990 iocoerce->coerceformat = cformat;
993 return (
Node *) iocoerce;
997 elog(
ERROR,
"unsupported pathtype %d in build_coercion_expression",
1020 int32 baseTypeMod = -1;
1036 else if (node &&
IsA(node,
Var) &&
1039 int rtindex = ((
Var *) node)->varno;
1040 int sublevels_up = ((
Var *) node)->varlevelsup;
1041 int vlocation = ((
Var *) node)->location;
1049 (
errcode(ERRCODE_CANNOT_COERCE),
1050 errmsg(
"cannot cast type %s to %s",
1066 for (
i = 0;
i < tupdesc->
natts;
i++)
1074 if (attr->attisdropped)
1087 (
errcode(ERRCODE_CANNOT_COERCE),
1088 errmsg(
"cannot cast type %s to %s",
1091 errdetail(
"Input has too few columns."),
1105 (
errcode(ERRCODE_CANNOT_COERCE),
1106 errmsg(
"cannot cast type %s to %s",
1109 errdetail(
"Cannot cast type %s to %s in column %d.",
1114 newargs =
lappend(newargs, cexpr);
1120 (
errcode(ERRCODE_CANNOT_COERCE),
1121 errmsg(
"cannot cast type %s to %s",
1124 errdetail(
"Input has too many columns."),
1130 rowexpr->
args = newargs;
1131 rowexpr->row_typeid = baseTypeId;
1132 rowexpr->row_format = cformat;
1133 rowexpr->colnames =
NIL;
1137 if (baseTypeId != targetTypeId)
1141 baseTypeId, baseTypeMod,
1143 ccontext, cformat, location,
1147 return (
Node *) rowexpr;
1162 const char *constructName)
1166 if (inputTypeId != BOOLOID)
1175 if (newnode == NULL)
1177 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1179 errmsg(
"argument of %s must be type %s, not type %s",
1180 constructName,
"boolean",
1188 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1190 errmsg(
"argument of %s must not return a set",
1209 Oid targetTypeId,
int32 targetTypmod,
1210 const char *constructName)
1214 if (inputTypeId != targetTypeId)
1219 targetTypeId, targetTypmod,
1223 if (newnode == NULL)
1225 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1227 errmsg(
"argument of %s must be type %s, not type %s",
1237 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1239 errmsg(
"argument of %s must not return a set",
1259 const char *constructName)
1278 int coerce_location,
1281 if (coerce_location >= 0)
1326 if (ptype != UNKNOWNOID)
1339 *which_expr = pexpr;
1358 if (ntype != UNKNOWNOID && ntype != ptype)
1364 if (ptype == UNKNOWNOID)
1369 pcategory = ncategory;
1370 pispreferred = nispreferred;
1372 else if (ncategory != pcategory)
1380 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1383 errmsg(
"%s types %s and %s cannot be matched",
1389 else if (!pispreferred &&
1399 pcategory = ncategory;
1400 pispreferred = nispreferred;
1416 if (ptype == UNKNOWNOID)
1420 *which_expr = pexpr;
1454 if (ptype != UNKNOWNOID)
1456 for (;
i < nargs;
i++)
1458 if (typeids[
i] != ptype)
1472 for (;
i < nargs;
i++)
1477 if (ntype != UNKNOWNOID && ntype != ptype)
1483 if (ptype == UNKNOWNOID)
1487 pcategory = ncategory;
1488 pispreferred = nispreferred;
1490 else if (ncategory != pcategory)
1498 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1499 errmsg(
"argument types %s and %s cannot be matched",
1503 else if (!pispreferred &&
1512 pcategory = ncategory;
1513 pispreferred = nispreferred;
1519 if (ptype == UNKNOWNOID)
1542 if (inputTypeId == targetTypeId)
1545 node =
coerce_type(pstate, node, inputTypeId, targetTypeId, -1,
1549 (
errcode(ERRCODE_CANNOT_COERCE),
1551 errmsg(
"%s could not convert type %s to %s",
1593 for (
int i = 0;
i < nargs;
i++)
1703 const Oid *declared_arg_types,
1715 bool have_anynonarray =
false;
1716 bool have_anyenum =
false;
1717 bool have_anycompatible_nonarray =
false;
1718 int n_anycompatible_args = 0;
1726 for (
int j = 0;
j < nargs;
j++)
1728 Oid decl_type = declared_arg_types[
j];
1729 Oid actual_type = actual_arg_types[
j];
1731 if (decl_type == ANYELEMENTOID ||
1732 decl_type == ANYNONARRAYOID ||
1733 decl_type == ANYENUMOID)
1735 if (decl_type == ANYNONARRAYOID)
1736 have_anynonarray =
true;
1737 else if (decl_type == ANYENUMOID)
1738 have_anyenum =
true;
1739 if (actual_type == UNKNOWNOID)
1741 if (
OidIsValid(elem_typeid) && actual_type != elem_typeid)
1743 elem_typeid = actual_type;
1745 else if (decl_type == ANYARRAYOID)
1747 if (actual_type == UNKNOWNOID)
1750 if (
OidIsValid(array_typeid) && actual_type != array_typeid)
1752 array_typeid = actual_type;
1754 else if (decl_type == ANYRANGEOID)
1756 if (actual_type == UNKNOWNOID)
1759 if (
OidIsValid(range_typeid) && actual_type != range_typeid)
1761 range_typeid = actual_type;
1763 else if (decl_type == ANYMULTIRANGEOID)
1765 if (actual_type == UNKNOWNOID)
1768 if (
OidIsValid(multirange_typeid) && actual_type != multirange_typeid)
1770 multirange_typeid = actual_type;
1772 else if (decl_type == ANYCOMPATIBLEOID ||
1773 decl_type == ANYCOMPATIBLENONARRAYOID)
1775 if (decl_type == ANYCOMPATIBLENONARRAYOID)
1776 have_anycompatible_nonarray =
true;
1777 if (actual_type == UNKNOWNOID)
1780 anycompatible_actual_types[n_anycompatible_args++] = actual_type;
1782 else if (decl_type == ANYCOMPATIBLEARRAYOID)
1786 if (actual_type == UNKNOWNOID)
1793 anycompatible_actual_types[n_anycompatible_args++] = elem_type;
1795 else if (decl_type == ANYCOMPATIBLERANGEOID)
1797 if (actual_type == UNKNOWNOID)
1803 if (anycompatible_range_typeid != actual_type)
1808 anycompatible_range_typeid = actual_type;
1810 if (!
OidIsValid(anycompatible_range_typelem))
1813 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
1816 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
1818 if (actual_type == UNKNOWNOID)
1821 if (
OidIsValid(anycompatible_multirange_typeid))
1824 if (anycompatible_multirange_typeid != actual_type)
1829 anycompatible_multirange_typeid = actual_type;
1831 if (!
OidIsValid(anycompatible_multirange_typelem))
1841 if (array_typeid == ANYARRAYOID)
1869 elem_typeid = array_typelem;
1871 else if (array_typelem != elem_typeid)
1882 Oid multirange_typelem;
1891 range_typeid = multirange_typelem;
1896 else if (multirange_typelem != range_typeid)
1915 elem_typeid = range_typelem;
1917 else if (range_typelem != elem_typeid)
1924 if (have_anynonarray)
1939 if (
OidIsValid(anycompatible_multirange_typeid))
1943 if (anycompatible_multirange_typelem !=
1944 anycompatible_range_typeid)
1949 anycompatible_range_typeid = anycompatible_multirange_typelem;
1951 if (!
OidIsValid(anycompatible_range_typelem))
1954 anycompatible_actual_types[n_anycompatible_args++] =
1955 anycompatible_range_typelem;
1960 if (n_anycompatible_args > 0)
1962 Oid anycompatible_typeid;
1964 anycompatible_typeid =
1966 anycompatible_actual_types,
1974 n_anycompatible_args,
1975 anycompatible_actual_types))
1978 if (have_anycompatible_nonarray)
1994 if (
OidIsValid(anycompatible_range_typelem) &&
1995 anycompatible_range_typelem != anycompatible_typeid)
2097 Oid *declared_arg_types,
2102 bool have_poly_anycompatible =
false;
2103 bool have_poly_unknowns =
false;
2114 bool have_anynonarray = (rettype == ANYNONARRAYOID);
2115 bool have_anyenum = (rettype == ANYENUMOID);
2116 bool have_anymultirange = (rettype == ANYMULTIRANGEOID);
2117 bool have_anycompatible_nonarray = (rettype == ANYCOMPATIBLENONARRAYOID);
2118 bool have_anycompatible_array = (rettype == ANYCOMPATIBLEARRAYOID);
2119 bool have_anycompatible_range = (rettype == ANYCOMPATIBLERANGEOID);
2120 bool have_anycompatible_multirange = (rettype == ANYCOMPATIBLEMULTIRANGEOID);
2121 int n_poly_args = 0;
2122 int n_anycompatible_args = 0;
2130 for (
int j = 0;
j < nargs;
j++)
2132 Oid decl_type = declared_arg_types[
j];
2133 Oid actual_type = actual_arg_types[
j];
2135 if (decl_type == ANYELEMENTOID ||
2136 decl_type == ANYNONARRAYOID ||
2137 decl_type == ANYENUMOID)
2140 if (decl_type == ANYNONARRAYOID)
2141 have_anynonarray =
true;
2142 else if (decl_type == ANYENUMOID)
2143 have_anyenum =
true;
2144 if (actual_type == UNKNOWNOID)
2146 have_poly_unknowns =
true;
2149 if (allow_poly && decl_type == actual_type)
2151 if (
OidIsValid(elem_typeid) && actual_type != elem_typeid)
2153 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2154 errmsg(
"arguments declared \"%s\" are not all alike",
"anyelement"),
2158 elem_typeid = actual_type;
2160 else if (decl_type == ANYARRAYOID)
2163 if (actual_type == UNKNOWNOID)
2165 have_poly_unknowns =
true;
2168 if (allow_poly && decl_type == actual_type)
2171 if (
OidIsValid(array_typeid) && actual_type != array_typeid)
2173 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2174 errmsg(
"arguments declared \"%s\" are not all alike",
"anyarray"),
2178 array_typeid = actual_type;
2180 else if (decl_type == ANYRANGEOID)
2183 if (actual_type == UNKNOWNOID)
2185 have_poly_unknowns =
true;
2188 if (allow_poly && decl_type == actual_type)
2191 if (
OidIsValid(range_typeid) && actual_type != range_typeid)
2193 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2194 errmsg(
"arguments declared \"%s\" are not all alike",
"anyrange"),
2198 range_typeid = actual_type;
2200 else if (decl_type == ANYMULTIRANGEOID)
2203 have_anymultirange =
true;
2204 if (actual_type == UNKNOWNOID)
2206 have_poly_unknowns =
true;
2209 if (allow_poly && decl_type == actual_type)
2212 if (
OidIsValid(multirange_typeid) && actual_type != multirange_typeid)
2214 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2215 errmsg(
"arguments declared \"%s\" are not all alike",
"anymultirange"),
2219 multirange_typeid = actual_type;
2221 else if (decl_type == ANYCOMPATIBLEOID ||
2222 decl_type == ANYCOMPATIBLENONARRAYOID)
2224 have_poly_anycompatible =
true;
2225 if (decl_type == ANYCOMPATIBLENONARRAYOID)
2226 have_anycompatible_nonarray =
true;
2227 if (actual_type == UNKNOWNOID)
2229 if (allow_poly && decl_type == actual_type)
2232 anycompatible_actual_types[n_anycompatible_args++] = actual_type;
2234 else if (decl_type == ANYCOMPATIBLEARRAYOID)
2236 Oid anycompatible_elem_type;
2238 have_poly_anycompatible =
true;
2239 have_anycompatible_array =
true;
2240 if (actual_type == UNKNOWNOID)
2242 if (allow_poly && decl_type == actual_type)
2248 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2249 errmsg(
"argument declared %s is not an array but type %s",
2250 "anycompatiblearray",
2253 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_elem_type;
2255 else if (decl_type == ANYCOMPATIBLERANGEOID)
2257 have_poly_anycompatible =
true;
2258 have_anycompatible_range =
true;
2259 if (actual_type == UNKNOWNOID)
2261 if (allow_poly && decl_type == actual_type)
2267 if (anycompatible_range_typeid != actual_type)
2269 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2270 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblerange"),
2277 anycompatible_range_typeid = actual_type;
2279 if (!
OidIsValid(anycompatible_range_typelem))
2281 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2282 errmsg(
"argument declared %s is not a range type but type %s",
2283 "anycompatiblerange",
2286 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
2289 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
2291 have_poly_anycompatible =
true;
2292 have_anycompatible_multirange =
true;
2293 if (actual_type == UNKNOWNOID)
2295 if (allow_poly && decl_type == actual_type)
2298 if (
OidIsValid(anycompatible_multirange_typeid))
2301 if (anycompatible_multirange_typeid != actual_type)
2303 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2304 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblemultirange"),
2311 anycompatible_multirange_typeid = actual_type;
2313 if (!
OidIsValid(anycompatible_multirange_typelem))
2315 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2316 errmsg(
"argument declared %s is not a multirange type but type %s",
2317 "anycompatiblemultirange",
2328 if (n_poly_args == 0 && !have_poly_anycompatible)
2339 if (array_typeid == ANYARRAYOID)
2348 if (n_poly_args != 1 ||
2349 (rettype != ANYARRAYOID &&
2350 IsPolymorphicTypeFamily1(rettype)))
2352 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2353 errmsg(
"cannot determine element type of \"anyarray\" argument")));
2354 array_typelem = ANYELEMENTOID;
2361 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2362 errmsg(
"argument declared %s is not an array but type %s",
2372 elem_typeid = array_typelem;
2374 else if (array_typelem != elem_typeid)
2378 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2379 errmsg(
"argument declared %s is not consistent with argument declared %s",
2380 "anyarray",
"anyelement"),
2390 Oid multirange_typelem;
2395 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2396 errmsg(
"argument declared %s is not a multirange type but type %s",
2403 range_typeid = multirange_typelem;
2405 else if (multirange_typelem != range_typeid)
2409 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2410 errmsg(
"argument declared %s is not consistent with argument declared %s",
2411 "anymultirange",
"anyrange"),
2417 else if (have_anymultirange &&
OidIsValid(range_typeid))
2431 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2432 errmsg(
"argument declared %s is not a range type but type %s",
2442 elem_typeid = range_typelem;
2444 else if (range_typelem != elem_typeid)
2448 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2449 errmsg(
"argument declared %s is not consistent with argument declared %s",
2450 "anyrange",
"anyelement"),
2461 elem_typeid = ANYELEMENTOID;
2462 array_typeid = ANYARRAYOID;
2463 range_typeid = ANYRANGEOID;
2464 multirange_typeid = ANYMULTIRANGEOID;
2473 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2474 errmsg(
"could not determine polymorphic type because input has type %s",
2479 if (have_anynonarray && elem_typeid != ANYELEMENTOID)
2487 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2488 errmsg(
"type matched to anynonarray is an array type: %s",
2492 if (have_anyenum && elem_typeid != ANYELEMENTOID)
2497 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2498 errmsg(
"type matched to anyenum is not an enum type: %s",
2504 if (have_poly_anycompatible)
2507 if (
OidIsValid(anycompatible_multirange_typeid))
2511 if (anycompatible_multirange_typelem !=
2512 anycompatible_range_typeid)
2514 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2515 errmsg(
"argument declared %s is not consistent with argument declared %s",
2516 "anycompatiblemultirange",
2517 "anycompatiblerange"),
2524 anycompatible_range_typeid = anycompatible_multirange_typelem;
2526 if (!
OidIsValid(anycompatible_range_typelem))
2528 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2529 errmsg(
"argument declared %s is not a multirange type but type %s",
2530 "anycompatiblemultirange",
2533 have_anycompatible_range =
true;
2535 anycompatible_actual_types[n_anycompatible_args++] =
2536 anycompatible_range_typelem;
2539 else if (have_anycompatible_multirange &&
2546 if (n_anycompatible_args > 0)
2548 anycompatible_typeid =
2550 anycompatible_actual_types,
2555 n_anycompatible_args,
2556 anycompatible_actual_types))
2558 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2559 errmsg(
"arguments of anycompatible family cannot be cast to a common type")));
2561 if (have_anycompatible_array)
2563 anycompatible_array_typeid =
get_array_type(anycompatible_typeid);
2566 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2567 errmsg(
"could not find array type for data type %s",
2571 if (have_anycompatible_range)
2576 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2577 errmsg(
"could not determine polymorphic type %s because input has type %s",
2578 "anycompatiblerange",
"unknown")));
2584 if (anycompatible_range_typelem != anycompatible_typeid)
2586 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2587 errmsg(
"anycompatiblerange type %s does not match anycompatible type %s",
2592 if (have_anycompatible_multirange)
2595 if (!
OidIsValid(anycompatible_multirange_typeid))
2597 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2598 errmsg(
"could not determine polymorphic type %s because input has type %s",
2599 "anycompatiblemultirange",
"unknown")));
2605 if (anycompatible_range_typelem != anycompatible_typeid)
2607 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2608 errmsg(
"anycompatiblemultirange type %s does not match anycompatible type %s",
2613 if (have_anycompatible_nonarray)
2621 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2622 errmsg(
"type matched to anycompatiblenonarray is an array type: %s",
2630 anycompatible_typeid = ANYCOMPATIBLEOID;
2631 anycompatible_array_typeid = ANYCOMPATIBLEARRAYOID;
2632 anycompatible_range_typeid = ANYCOMPATIBLERANGEOID;
2633 anycompatible_multirange_typeid = ANYCOMPATIBLEMULTIRANGEOID;
2643 anycompatible_typeid = TEXTOID;
2644 anycompatible_array_typeid = TEXTARRAYOID;
2645 if (have_anycompatible_range)
2647 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2648 errmsg(
"could not determine polymorphic type %s because input has type %s",
2649 "anycompatiblerange",
"unknown")));
2650 if (have_anycompatible_multirange)
2652 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2653 errmsg(
"could not determine polymorphic type %s because input has type %s",
2654 "anycompatiblemultirange",
"unknown")));
2659 for (
int j = 0;
j < nargs;
j++)
2661 Oid decl_type = declared_arg_types[
j];
2663 if (decl_type == ANYCOMPATIBLEOID ||
2664 decl_type == ANYCOMPATIBLENONARRAYOID)
2665 declared_arg_types[
j] = anycompatible_typeid;
2666 else if (decl_type == ANYCOMPATIBLEARRAYOID)
2667 declared_arg_types[
j] = anycompatible_array_typeid;
2668 else if (decl_type == ANYCOMPATIBLERANGEOID)
2669 declared_arg_types[
j] = anycompatible_range_typeid;
2670 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
2671 declared_arg_types[
j] = anycompatible_multirange_typeid;
2683 if (have_poly_unknowns)
2685 for (
int j = 0;
j < nargs;
j++)
2687 Oid decl_type = declared_arg_types[
j];
2688 Oid actual_type = actual_arg_types[
j];
2690 if (actual_type != UNKNOWNOID)
2693 if (decl_type == ANYELEMENTOID ||
2694 decl_type == ANYNONARRAYOID ||
2695 decl_type == ANYENUMOID)
2696 declared_arg_types[
j] = elem_typeid;
2697 else if (decl_type == ANYARRAYOID)
2704 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2705 errmsg(
"could not find array type for data type %s",
2708 declared_arg_types[
j] = array_typeid;
2710 else if (decl_type == ANYRANGEOID)
2716 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2717 errmsg(
"could not determine polymorphic type %s because input has type %s",
2718 "anyrange",
"unknown")));
2720 declared_arg_types[
j] = range_typeid;
2722 else if (decl_type == ANYMULTIRANGEOID)
2728 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2729 errmsg(
"could not determine polymorphic type %s because input has type %s",
2730 "anymultirange",
"unknown")));
2732 declared_arg_types[
j] = multirange_typeid;
2738 if (rettype == ANYELEMENTOID ||
2739 rettype == ANYNONARRAYOID ||
2740 rettype == ANYENUMOID)
2744 if (rettype == ANYARRAYOID)
2751 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2752 errmsg(
"could not find array type for data type %s",
2755 return array_typeid;
2759 if (rettype == ANYRANGEOID)
2764 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2765 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2766 "anyrange",
"unknown")));
2767 return range_typeid;
2771 if (rettype == ANYMULTIRANGEOID)
2776 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2777 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2778 "anymultirange",
"unknown")));
2779 return multirange_typeid;
2783 if (rettype == ANYCOMPATIBLEOID ||
2784 rettype == ANYCOMPATIBLENONARRAYOID)
2789 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2791 return anycompatible_typeid;
2795 if (rettype == ANYCOMPATIBLEARRAYOID)
2800 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2802 return anycompatible_array_typeid;
2806 if (rettype == ANYCOMPATIBLERANGEOID)
2811 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2813 return anycompatible_range_typeid;
2817 if (rettype == ANYCOMPATIBLEMULTIRANGEOID)
2820 if (!
OidIsValid(anycompatible_multirange_typeid))
2822 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2824 return anycompatible_multirange_typeid;
2841 const Oid *declared_arg_types,
2844 if (ret_type == ANYRANGEOID || ret_type == ANYMULTIRANGEOID)
2851 for (
int i = 0;
i < nargs;
i++)
2853 if (declared_arg_types[
i] == ANYRANGEOID ||
2854 declared_arg_types[
i] == ANYMULTIRANGEOID)
2857 return psprintf(
_(
"A result of type %s requires at least one input of type anyrange or anymultirange."),
2860 else if (ret_type == ANYCOMPATIBLERANGEOID || ret_type == ANYCOMPATIBLEMULTIRANGEOID)
2868 for (
int i = 0;
i < nargs;
i++)
2870 if (declared_arg_types[
i] == ANYCOMPATIBLERANGEOID ||
2871 declared_arg_types[
i] == ANYCOMPATIBLEMULTIRANGEOID)
2874 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatiblerange or anycompatiblemultirange."),
2877 else if (IsPolymorphicTypeFamily1(ret_type))
2880 for (
int i = 0;
i < nargs;
i++)
2882 if (IsPolymorphicTypeFamily1(declared_arg_types[
i]))
2886 return psprintf(
_(
"A result of type %s requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange."),
2889 else if (IsPolymorphicTypeFamily2(ret_type))
2892 for (
int i = 0;
i < nargs;
i++)
2894 if (IsPolymorphicTypeFamily2(declared_arg_types[
i]))
2898 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, anycompatiblerange, or anycompatiblemultirange."),
2918 const Oid *declared_arg_types,
2921 if (ret_type == INTERNALOID)
2923 for (
int i = 0;
i < nargs;
i++)
2925 if (declared_arg_types[
i] == ret_type)
2928 return pstrdup(
_(
"A result of type internal requires at least one input of type internal."));
2944 bool typispreferred;
2947 Assert(typcategory != TYPCATEGORY_INVALID);
2963 bool typispreferred;
2966 if (category == typcategory || category == TYPCATEGORY_INVALID)
2967 return typispreferred;
3020 if (srctype == targettype)
3024 if (targettype == ANYOID || targettype == ANYELEMENTOID ||
3025 targettype == ANYCOMPATIBLEOID)
3033 if (srctype == targettype)
3037 if (targettype == ANYARRAYOID || targettype == ANYCOMPATIBLEARRAYOID)
3042 if (targettype == ANYNONARRAYOID || targettype == ANYCOMPATIBLENONARRAYOID)
3047 if (targettype == ANYENUMOID)
3052 if (targettype == ANYRANGEOID || targettype == ANYCOMPATIBLERANGEOID)
3057 if (targettype == ANYMULTIRANGEOID || targettype == ANYCOMPATIBLEMULTIRANGEOID)
3062 if (targettype == RECORDOID)
3067 if (targettype == RECORDARRAYOID)
3079 result = (castForm->castmethod == COERCION_METHOD_BINARY &&
3080 castForm->castcontext == COERCION_CODE_IMPLICIT);
3083 *castoid = castForm->oid;
3134 if (sourceTypeId == targetTypeId)
3148 switch (castForm->castcontext)
3150 case COERCION_CODE_IMPLICIT:
3153 case COERCION_CODE_ASSIGNMENT:
3156 case COERCION_CODE_EXPLICIT:
3160 elog(
ERROR,
"unrecognized castcontext: %d",
3161 (
int) castForm->castcontext);
3167 if (ccontext >= castcontext)
3169 switch (castForm->castmethod)
3171 case COERCION_METHOD_FUNCTION:
3173 *funcid = castForm->castfunc;
3175 case COERCION_METHOD_INOUT:
3178 case COERCION_METHOD_BINARY:
3182 elog(
ERROR,
"unrecognized castmethod: %d",
3183 (
int) castForm->castmethod);
3204 if (targetTypeId != OIDVECTOROID && targetTypeId != INT2VECTOROID)
3296 if (IsTrueArrayType(typeForm))
3299 typeId = typeForm->typelem;
3313 *funcid = castForm->castfunc;
3348 bool result =
false;
3357 elog(
ERROR,
"cache lookup failed for relation %u", relid);
3360 if (reltup->reloftype == reloftypeId)
#define InvalidAttrNumber
#define Assert(condition)
#define OidIsValid(objectId)
bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define PG_DETOAST_DATUM(datum)
#define HeapTupleIsValid(tuple)
List * lappend(List *list, void *datum)
Oid get_range_subtype(Oid rangeOid)
Oid get_element_type(Oid typid)
bool type_is_range(Oid typid)
bool type_is_enum(Oid typid)
Oid get_multirange_range(Oid multirangeOid)
Oid get_range_multirange(Oid rangeOid)
bool type_is_collatable(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)
bool type_is_multirange(Oid typid)
#define type_is_array(typid)
#define type_is_array_domain(typid)
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
RelabelType * makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
char * pstrdup(const char *in)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
int exprLocation(const Node *expr)
bool expression_returns_set(Node *clause)
#define IsA(nodeptr, _type_)
TYPCATEGORY TypeCategory(Oid type)
static bool verify_common_type_from_oids(Oid common_type, int nargs, const Oid *typeids)
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
static bool typeIsOfTypedTable(Oid reltypeId, Oid reloftypeId)
static Node * coerce_record_to_complex(ParseState *pstate, Node *node, Oid targetTypeId, CoercionContext ccontext, CoercionForm cformat, int location)
CoercionPathType find_typmod_coercion_function(Oid typeId, Oid *funcid)
Node * coerce_to_specific_type_typmod(ParseState *pstate, Node *node, Oid targetTypeId, int32 targetTypmod, const char *constructName)
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
static Node * coerce_type_typmod(Node *node, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
bool check_generic_type_consistency(const Oid *actual_arg_types, const Oid *declared_arg_types, int nargs)
bool verify_common_type(Oid common_type, List *exprs)
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)
int parser_coercion_errposition(ParseState *pstate, int coerce_location, Node *input_expr)
int32 select_common_typmod(ParseState *pstate, List *exprs, Oid common_type)
static Node * build_coercion_expression(Node *node, CoercionPathType pathtype, Oid funcId, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location)
Node * coerce_to_specific_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
char * check_valid_internal_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
static bool is_complex_array(Oid typid)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
bool IsPreferredType(TYPCATEGORY category, Oid type)
static void hide_coercion_node(Node *node)
Oid select_common_type(ParseState *pstate, List *exprs, const char *context, Node **which_expr)
char * check_valid_polymorphic_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
static Oid select_common_type_from_oids(int nargs, const Oid *typeids, bool noerror)
bool IsBinaryCoercibleWithCast(Oid srctype, Oid targettype, Oid *castoid)
@ COERCION_PATH_COERCEVIAIO
@ COERCION_PATH_ARRAYCOERCE
@ COERCION_PATH_RELABELTYPE
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
int parser_errposition(ParseState *pstate, int location)
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
List * expandNSItemVars(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
Oid typeOrDomainTypeRelid(Oid type_id)
Oid typeTypeCollation(Type typ)
Datum stringTypeDatum(Type tp, char *string, int32 atttypmod)
char * typeTypeName(Type t)
#define ISCOMPLEX(typeid)
FormData_pg_attribute * Form_pg_attribute
FormData_pg_cast * Form_pg_cast
FormData_pg_class * Form_pg_class
bool typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
#define for_each_cell(cell, lst, initcell)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
static ListCell * list_second_cell(const List *l)
FormData_pg_proc * Form_pg_proc
FormData_pg_type * Form_pg_type
static Datum PointerGetDatum(const void *X)
static char * DatumGetCString(Datum X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
char * psprintf(const char *fmt,...)
CoerceParamHook p_coerce_param_hook
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)