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;
420 baseTypeMod = targetTypeMod;
433 baseTypeId, baseTypeMod,
434 ccontext, cformat, location);
440 if (targetTypeId != baseTypeId)
443 ccontext, cformat, location,
459 ccontext, cformat, location,
480 if (inputTypeId == RECORDOID &&
485 ccontext, cformat, location);
487 if (targetTypeId == RECORDOID &&
495 if (inputTypeId == RECORDARRAYOID &&
502 if (targetTypeId == RECORDARRAYOID &&
526 if (baseTypeId != inputTypeId)
538 r->convertformat = cformat;
543 elog(
ERROR,
"failed to find conversion function from %s to %s",
560 bool have_generics =
false;
564 for (
i = 0;
i < nargs;
i++)
566 Oid inputTypeId = input_typeids[
i];
567 Oid targetTypeId = target_typeids[
i];
572 if (inputTypeId == targetTypeId)
576 if (targetTypeId == ANYOID)
580 if (IsPolymorphicType(targetTypeId))
582 have_generics =
true;
590 if (inputTypeId == UNKNOWNOID)
606 if (inputTypeId == RECORDOID &&
613 if (targetTypeId == RECORDOID &&
623 if (inputTypeId == RECORDARRAYOID &&
631 if (targetTypeId == RECORDARRAYOID &&
677 bool hideInputCoercion)
685 if (baseTypeId == typeId)
689 if (hideInputCoercion)
717 result->resulttypmod = -1;
719 result->coercionformat = cformat;
722 return (
Node *) result;
754 bool hideInputCoercion)
764 if (hideInputCoercion)
772 if (targetTypMod < 0)
780 targetTypeId, targetTypMod,
781 ccontext, cformat, location);
792 cformat, location,
false);
840 Oid targetTypeId,
int32 targetTypMod,
853 elog(
ERROR,
"cache lookup failed for function %u", funcId);
863 Assert(!procstruct->proretset);
864 Assert(procstruct->prokind == PROKIND_FUNCTION);
865 nargs = procstruct->pronargs;
866 Assert(nargs >= 1 && nargs <= 3);
868 Assert(nargs < 2 || procstruct->proargtypes.values[1] == INT4OID);
869 Assert(nargs < 3 || procstruct->proargtypes.values[2] == BOOLOID);
916 return (
Node *) fexpr;
923 Oid sourceBaseTypeId;
924 int32 sourceBaseTypeMod;
925 Oid targetElementType;
945 ctest->typeMod = sourceBaseTypeMod;
960 if (elemexpr == NULL)
961 elog(
ERROR,
"failed to coerce array element type as expected");
973 acoerce->coerceformat = cformat;
976 return (
Node *) acoerce;
988 iocoerce->coerceformat = cformat;
991 return (
Node *) iocoerce;
995 elog(
ERROR,
"unsupported pathtype %d in build_coercion_expression",
1018 int32 baseTypeMod = -1;
1034 else if (node &&
IsA(node,
Var) &&
1037 int rtindex = ((
Var *) node)->varno;
1038 int sublevels_up = ((
Var *) node)->varlevelsup;
1039 int vlocation = ((
Var *) node)->location;
1047 (
errcode(ERRCODE_CANNOT_COERCE),
1048 errmsg(
"cannot cast type %s to %s",
1064 for (
i = 0;
i < tupdesc->
natts;
i++)
1072 if (attr->attisdropped)
1085 (
errcode(ERRCODE_CANNOT_COERCE),
1086 errmsg(
"cannot cast type %s to %s",
1089 errdetail(
"Input has too few columns."),
1103 (
errcode(ERRCODE_CANNOT_COERCE),
1104 errmsg(
"cannot cast type %s to %s",
1107 errdetail(
"Cannot cast type %s to %s in column %d.",
1112 newargs =
lappend(newargs, cexpr);
1118 (
errcode(ERRCODE_CANNOT_COERCE),
1119 errmsg(
"cannot cast type %s to %s",
1122 errdetail(
"Input has too many columns."),
1128 rowexpr->
args = newargs;
1129 rowexpr->row_typeid = baseTypeId;
1130 rowexpr->row_format = cformat;
1131 rowexpr->colnames =
NIL;
1135 if (baseTypeId != targetTypeId)
1139 baseTypeId, baseTypeMod,
1141 ccontext, cformat, location,
1145 return (
Node *) rowexpr;
1160 const char *constructName)
1164 if (inputTypeId != BOOLOID)
1173 if (newnode == NULL)
1175 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1177 errmsg(
"argument of %s must be type %s, not type %s",
1178 constructName,
"boolean",
1186 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1188 errmsg(
"argument of %s must not return a set",
1207 Oid targetTypeId,
int32 targetTypmod,
1208 const char *constructName)
1212 if (inputTypeId != targetTypeId)
1217 targetTypeId, targetTypmod,
1221 if (newnode == NULL)
1223 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1225 errmsg(
"argument of %s must be type %s, not type %s",
1235 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1237 errmsg(
"argument of %s must not return a set",
1257 const char *constructName)
1272 int typlen,
bool typbyval)
1276 int32 baseTypeMod = typmod;
1290 if (typid != baseTypeId)
1292 baseTypeId, baseTypeMod,
1313 int coerce_location,
1316 if (coerce_location >= 0)
1361 if (ptype != UNKNOWNOID)
1374 *which_expr = pexpr;
1393 if (ntype != UNKNOWNOID && ntype != ptype)
1399 if (ptype == UNKNOWNOID)
1404 pcategory = ncategory;
1405 pispreferred = nispreferred;
1407 else if (ncategory != pcategory)
1412 if (context == NULL)
1415 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1418 errmsg(
"%s types %s and %s cannot be matched",
1424 else if (!pispreferred &&
1434 pcategory = ncategory;
1435 pispreferred = nispreferred;
1451 if (ptype == UNKNOWNOID)
1455 *which_expr = pexpr;
1489 if (ptype != UNKNOWNOID)
1491 for (;
i < nargs;
i++)
1493 if (typeids[
i] != ptype)
1507 for (;
i < nargs;
i++)
1512 if (ntype != UNKNOWNOID && ntype != ptype)
1518 if (ptype == UNKNOWNOID)
1522 pcategory = ncategory;
1523 pispreferred = nispreferred;
1525 else if (ncategory != pcategory)
1533 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1534 errmsg(
"argument types %s and %s cannot be matched",
1538 else if (!pispreferred &&
1547 pcategory = ncategory;
1548 pispreferred = nispreferred;
1554 if (ptype == UNKNOWNOID)
1573 Oid targetTypeId,
const char *context)
1577 if (inputTypeId == targetTypeId)
1580 node =
coerce_type(pstate, node, inputTypeId, targetTypeId, -1,
1584 (
errcode(ERRCODE_CANNOT_COERCE),
1586 errmsg(
"%s could not convert type %s to %s",
1628 for (
int i = 0;
i < nargs;
i++)
1738 const Oid *declared_arg_types,
1750 bool have_anynonarray =
false;
1751 bool have_anyenum =
false;
1752 bool have_anycompatible_nonarray =
false;
1753 int n_anycompatible_args = 0;
1761 for (
int j = 0;
j < nargs;
j++)
1763 Oid decl_type = declared_arg_types[
j];
1764 Oid actual_type = actual_arg_types[
j];
1766 if (decl_type == ANYELEMENTOID ||
1767 decl_type == ANYNONARRAYOID ||
1768 decl_type == ANYENUMOID)
1770 if (decl_type == ANYNONARRAYOID)
1771 have_anynonarray =
true;
1772 else if (decl_type == ANYENUMOID)
1773 have_anyenum =
true;
1774 if (actual_type == UNKNOWNOID)
1776 if (
OidIsValid(elem_typeid) && actual_type != elem_typeid)
1778 elem_typeid = actual_type;
1780 else if (decl_type == ANYARRAYOID)
1782 if (actual_type == UNKNOWNOID)
1785 if (
OidIsValid(array_typeid) && actual_type != array_typeid)
1787 array_typeid = actual_type;
1789 else if (decl_type == ANYRANGEOID)
1791 if (actual_type == UNKNOWNOID)
1794 if (
OidIsValid(range_typeid) && actual_type != range_typeid)
1796 range_typeid = actual_type;
1798 else if (decl_type == ANYMULTIRANGEOID)
1800 if (actual_type == UNKNOWNOID)
1803 if (
OidIsValid(multirange_typeid) && actual_type != multirange_typeid)
1805 multirange_typeid = actual_type;
1807 else if (decl_type == ANYCOMPATIBLEOID ||
1808 decl_type == ANYCOMPATIBLENONARRAYOID)
1810 if (decl_type == ANYCOMPATIBLENONARRAYOID)
1811 have_anycompatible_nonarray =
true;
1812 if (actual_type == UNKNOWNOID)
1815 anycompatible_actual_types[n_anycompatible_args++] = actual_type;
1817 else if (decl_type == ANYCOMPATIBLEARRAYOID)
1821 if (actual_type == UNKNOWNOID)
1828 anycompatible_actual_types[n_anycompatible_args++] = elem_type;
1830 else if (decl_type == ANYCOMPATIBLERANGEOID)
1832 if (actual_type == UNKNOWNOID)
1838 if (anycompatible_range_typeid != actual_type)
1843 anycompatible_range_typeid = actual_type;
1845 if (!
OidIsValid(anycompatible_range_typelem))
1848 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
1851 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
1853 if (actual_type == UNKNOWNOID)
1856 if (
OidIsValid(anycompatible_multirange_typeid))
1859 if (anycompatible_multirange_typeid != actual_type)
1864 anycompatible_multirange_typeid = actual_type;
1866 if (!
OidIsValid(anycompatible_multirange_typelem))
1876 if (array_typeid == ANYARRAYOID)
1904 elem_typeid = array_typelem;
1906 else if (array_typelem != elem_typeid)
1917 Oid multirange_typelem;
1926 range_typeid = multirange_typelem;
1931 else if (multirange_typelem != range_typeid)
1950 elem_typeid = range_typelem;
1952 else if (range_typelem != elem_typeid)
1959 if (have_anynonarray)
1974 if (
OidIsValid(anycompatible_multirange_typeid))
1978 if (anycompatible_multirange_typelem !=
1979 anycompatible_range_typeid)
1984 anycompatible_range_typeid = anycompatible_multirange_typelem;
1986 if (!
OidIsValid(anycompatible_range_typelem))
1989 anycompatible_actual_types[n_anycompatible_args++] =
1990 anycompatible_range_typelem;
1995 if (n_anycompatible_args > 0)
1997 Oid anycompatible_typeid;
1999 anycompatible_typeid =
2001 anycompatible_actual_types,
2009 n_anycompatible_args,
2010 anycompatible_actual_types))
2013 if (have_anycompatible_nonarray)
2029 if (
OidIsValid(anycompatible_range_typelem) &&
2030 anycompatible_range_typelem != anycompatible_typeid)
2132 Oid *declared_arg_types,
2137 bool have_poly_anycompatible =
false;
2138 bool have_poly_unknowns =
false;
2149 bool have_anynonarray = (rettype == ANYNONARRAYOID);
2150 bool have_anyenum = (rettype == ANYENUMOID);
2151 bool have_anymultirange = (rettype == ANYMULTIRANGEOID);
2152 bool have_anycompatible_nonarray = (rettype == ANYCOMPATIBLENONARRAYOID);
2153 bool have_anycompatible_array = (rettype == ANYCOMPATIBLEARRAYOID);
2154 bool have_anycompatible_range = (rettype == ANYCOMPATIBLERANGEOID);
2155 bool have_anycompatible_multirange = (rettype == ANYCOMPATIBLEMULTIRANGEOID);
2156 int n_poly_args = 0;
2157 int n_anycompatible_args = 0;
2165 for (
int j = 0;
j < nargs;
j++)
2167 Oid decl_type = declared_arg_types[
j];
2168 Oid actual_type = actual_arg_types[
j];
2170 if (decl_type == ANYELEMENTOID ||
2171 decl_type == ANYNONARRAYOID ||
2172 decl_type == ANYENUMOID)
2175 if (decl_type == ANYNONARRAYOID)
2176 have_anynonarray =
true;
2177 else if (decl_type == ANYENUMOID)
2178 have_anyenum =
true;
2179 if (actual_type == UNKNOWNOID)
2181 have_poly_unknowns =
true;
2184 if (allow_poly && decl_type == actual_type)
2186 if (
OidIsValid(elem_typeid) && actual_type != elem_typeid)
2188 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2189 errmsg(
"arguments declared \"%s\" are not all alike",
"anyelement"),
2193 elem_typeid = actual_type;
2195 else if (decl_type == ANYARRAYOID)
2198 if (actual_type == UNKNOWNOID)
2200 have_poly_unknowns =
true;
2203 if (allow_poly && decl_type == actual_type)
2206 if (
OidIsValid(array_typeid) && actual_type != array_typeid)
2208 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2209 errmsg(
"arguments declared \"%s\" are not all alike",
"anyarray"),
2213 array_typeid = actual_type;
2215 else if (decl_type == ANYRANGEOID)
2218 if (actual_type == UNKNOWNOID)
2220 have_poly_unknowns =
true;
2223 if (allow_poly && decl_type == actual_type)
2226 if (
OidIsValid(range_typeid) && actual_type != range_typeid)
2228 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2229 errmsg(
"arguments declared \"%s\" are not all alike",
"anyrange"),
2233 range_typeid = actual_type;
2235 else if (decl_type == ANYMULTIRANGEOID)
2238 have_anymultirange =
true;
2239 if (actual_type == UNKNOWNOID)
2241 have_poly_unknowns =
true;
2244 if (allow_poly && decl_type == actual_type)
2247 if (
OidIsValid(multirange_typeid) && actual_type != multirange_typeid)
2249 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2250 errmsg(
"arguments declared \"%s\" are not all alike",
"anymultirange"),
2254 multirange_typeid = actual_type;
2256 else if (decl_type == ANYCOMPATIBLEOID ||
2257 decl_type == ANYCOMPATIBLENONARRAYOID)
2259 have_poly_anycompatible =
true;
2260 if (decl_type == ANYCOMPATIBLENONARRAYOID)
2261 have_anycompatible_nonarray =
true;
2262 if (actual_type == UNKNOWNOID)
2264 if (allow_poly && decl_type == actual_type)
2267 anycompatible_actual_types[n_anycompatible_args++] = actual_type;
2269 else if (decl_type == ANYCOMPATIBLEARRAYOID)
2271 Oid anycompatible_elem_type;
2273 have_poly_anycompatible =
true;
2274 have_anycompatible_array =
true;
2275 if (actual_type == UNKNOWNOID)
2277 if (allow_poly && decl_type == actual_type)
2283 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2284 errmsg(
"argument declared %s is not an array but type %s",
2285 "anycompatiblearray",
2288 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_elem_type;
2290 else if (decl_type == ANYCOMPATIBLERANGEOID)
2292 have_poly_anycompatible =
true;
2293 have_anycompatible_range =
true;
2294 if (actual_type == UNKNOWNOID)
2296 if (allow_poly && decl_type == actual_type)
2302 if (anycompatible_range_typeid != actual_type)
2304 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2305 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblerange"),
2312 anycompatible_range_typeid = actual_type;
2314 if (!
OidIsValid(anycompatible_range_typelem))
2316 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2317 errmsg(
"argument declared %s is not a range type but type %s",
2318 "anycompatiblerange",
2321 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
2324 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
2326 have_poly_anycompatible =
true;
2327 have_anycompatible_multirange =
true;
2328 if (actual_type == UNKNOWNOID)
2330 if (allow_poly && decl_type == actual_type)
2333 if (
OidIsValid(anycompatible_multirange_typeid))
2336 if (anycompatible_multirange_typeid != actual_type)
2338 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2339 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblemultirange"),
2346 anycompatible_multirange_typeid = actual_type;
2348 if (!
OidIsValid(anycompatible_multirange_typelem))
2350 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2351 errmsg(
"argument declared %s is not a multirange type but type %s",
2352 "anycompatiblemultirange",
2363 if (n_poly_args == 0 && !have_poly_anycompatible)
2374 if (array_typeid == ANYARRAYOID)
2383 if (n_poly_args != 1 ||
2384 (rettype != ANYARRAYOID &&
2385 IsPolymorphicTypeFamily1(rettype)))
2387 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2388 errmsg(
"cannot determine element type of \"anyarray\" argument")));
2389 array_typelem = ANYELEMENTOID;
2396 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2397 errmsg(
"argument declared %s is not an array but type %s",
2407 elem_typeid = array_typelem;
2409 else if (array_typelem != elem_typeid)
2413 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2414 errmsg(
"argument declared %s is not consistent with argument declared %s",
2415 "anyarray",
"anyelement"),
2425 Oid multirange_typelem;
2430 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2431 errmsg(
"argument declared %s is not a multirange type but type %s",
2438 range_typeid = multirange_typelem;
2440 else if (multirange_typelem != range_typeid)
2444 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2445 errmsg(
"argument declared %s is not consistent with argument declared %s",
2446 "anymultirange",
"anyrange"),
2452 else if (have_anymultirange &&
OidIsValid(range_typeid))
2466 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2467 errmsg(
"argument declared %s is not a range type but type %s",
2477 elem_typeid = range_typelem;
2479 else if (range_typelem != elem_typeid)
2483 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2484 errmsg(
"argument declared %s is not consistent with argument declared %s",
2485 "anyrange",
"anyelement"),
2496 elem_typeid = ANYELEMENTOID;
2497 array_typeid = ANYARRAYOID;
2498 range_typeid = ANYRANGEOID;
2499 multirange_typeid = ANYMULTIRANGEOID;
2508 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2509 errmsg(
"could not determine polymorphic type because input has type %s",
2514 if (have_anynonarray && elem_typeid != ANYELEMENTOID)
2522 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2523 errmsg(
"type matched to anynonarray is an array type: %s",
2527 if (have_anyenum && elem_typeid != ANYELEMENTOID)
2532 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2533 errmsg(
"type matched to anyenum is not an enum type: %s",
2539 if (have_poly_anycompatible)
2542 if (
OidIsValid(anycompatible_multirange_typeid))
2546 if (anycompatible_multirange_typelem !=
2547 anycompatible_range_typeid)
2549 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2550 errmsg(
"argument declared %s is not consistent with argument declared %s",
2551 "anycompatiblemultirange",
2552 "anycompatiblerange"),
2559 anycompatible_range_typeid = anycompatible_multirange_typelem;
2561 if (!
OidIsValid(anycompatible_range_typelem))
2563 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2564 errmsg(
"argument declared %s is not a multirange type but type %s",
2565 "anycompatiblemultirange",
2568 have_anycompatible_range =
true;
2570 anycompatible_actual_types[n_anycompatible_args++] =
2571 anycompatible_range_typelem;
2574 else if (have_anycompatible_multirange &&
2581 if (n_anycompatible_args > 0)
2583 anycompatible_typeid =
2585 anycompatible_actual_types,
2590 n_anycompatible_args,
2591 anycompatible_actual_types))
2593 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2594 errmsg(
"arguments of anycompatible family cannot be cast to a common type")));
2596 if (have_anycompatible_array)
2598 anycompatible_array_typeid =
get_array_type(anycompatible_typeid);
2601 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2602 errmsg(
"could not find array type for data type %s",
2606 if (have_anycompatible_range)
2611 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2612 errmsg(
"could not determine polymorphic type %s because input has type %s",
2613 "anycompatiblerange",
"unknown")));
2619 if (anycompatible_range_typelem != anycompatible_typeid)
2621 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2622 errmsg(
"anycompatiblerange type %s does not match anycompatible type %s",
2627 if (have_anycompatible_multirange)
2630 if (!
OidIsValid(anycompatible_multirange_typeid))
2632 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2633 errmsg(
"could not determine polymorphic type %s because input has type %s",
2634 "anycompatiblemultirange",
"unknown")));
2640 if (anycompatible_range_typelem != anycompatible_typeid)
2642 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2643 errmsg(
"anycompatiblemultirange type %s does not match anycompatible type %s",
2648 if (have_anycompatible_nonarray)
2656 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2657 errmsg(
"type matched to anycompatiblenonarray is an array type: %s",
2665 anycompatible_typeid = ANYCOMPATIBLEOID;
2666 anycompatible_array_typeid = ANYCOMPATIBLEARRAYOID;
2667 anycompatible_range_typeid = ANYCOMPATIBLERANGEOID;
2668 anycompatible_multirange_typeid = ANYCOMPATIBLEMULTIRANGEOID;
2678 anycompatible_typeid = TEXTOID;
2679 anycompatible_array_typeid = TEXTARRAYOID;
2680 if (have_anycompatible_range)
2682 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2683 errmsg(
"could not determine polymorphic type %s because input has type %s",
2684 "anycompatiblerange",
"unknown")));
2685 if (have_anycompatible_multirange)
2687 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2688 errmsg(
"could not determine polymorphic type %s because input has type %s",
2689 "anycompatiblemultirange",
"unknown")));
2694 for (
int j = 0;
j < nargs;
j++)
2696 Oid decl_type = declared_arg_types[
j];
2698 if (decl_type == ANYCOMPATIBLEOID ||
2699 decl_type == ANYCOMPATIBLENONARRAYOID)
2700 declared_arg_types[
j] = anycompatible_typeid;
2701 else if (decl_type == ANYCOMPATIBLEARRAYOID)
2702 declared_arg_types[
j] = anycompatible_array_typeid;
2703 else if (decl_type == ANYCOMPATIBLERANGEOID)
2704 declared_arg_types[
j] = anycompatible_range_typeid;
2705 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
2706 declared_arg_types[
j] = anycompatible_multirange_typeid;
2718 if (have_poly_unknowns)
2720 for (
int j = 0;
j < nargs;
j++)
2722 Oid decl_type = declared_arg_types[
j];
2723 Oid actual_type = actual_arg_types[
j];
2725 if (actual_type != UNKNOWNOID)
2728 if (decl_type == ANYELEMENTOID ||
2729 decl_type == ANYNONARRAYOID ||
2730 decl_type == ANYENUMOID)
2731 declared_arg_types[
j] = elem_typeid;
2732 else if (decl_type == ANYARRAYOID)
2739 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2740 errmsg(
"could not find array type for data type %s",
2743 declared_arg_types[
j] = array_typeid;
2745 else if (decl_type == ANYRANGEOID)
2751 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2752 errmsg(
"could not determine polymorphic type %s because input has type %s",
2753 "anyrange",
"unknown")));
2755 declared_arg_types[
j] = range_typeid;
2757 else if (decl_type == ANYMULTIRANGEOID)
2763 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2764 errmsg(
"could not determine polymorphic type %s because input has type %s",
2765 "anymultirange",
"unknown")));
2767 declared_arg_types[
j] = multirange_typeid;
2773 if (rettype == ANYELEMENTOID ||
2774 rettype == ANYNONARRAYOID ||
2775 rettype == ANYENUMOID)
2779 if (rettype == ANYARRAYOID)
2786 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2787 errmsg(
"could not find array type for data type %s",
2790 return array_typeid;
2794 if (rettype == ANYRANGEOID)
2799 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2800 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2801 "anyrange",
"unknown")));
2802 return range_typeid;
2806 if (rettype == ANYMULTIRANGEOID)
2811 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2812 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2813 "anymultirange",
"unknown")));
2814 return multirange_typeid;
2818 if (rettype == ANYCOMPATIBLEOID ||
2819 rettype == ANYCOMPATIBLENONARRAYOID)
2824 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2826 return anycompatible_typeid;
2830 if (rettype == ANYCOMPATIBLEARRAYOID)
2835 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2837 return anycompatible_array_typeid;
2841 if (rettype == ANYCOMPATIBLERANGEOID)
2846 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2848 return anycompatible_range_typeid;
2852 if (rettype == ANYCOMPATIBLEMULTIRANGEOID)
2855 if (!
OidIsValid(anycompatible_multirange_typeid))
2857 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2859 return anycompatible_multirange_typeid;
2876 const Oid *declared_arg_types,
2879 if (ret_type == ANYRANGEOID || ret_type == ANYMULTIRANGEOID)
2886 for (
int i = 0;
i < nargs;
i++)
2888 if (declared_arg_types[
i] == ANYRANGEOID ||
2889 declared_arg_types[
i] == ANYMULTIRANGEOID)
2892 return psprintf(
_(
"A result of type %s requires at least one input of type anyrange or anymultirange."),
2895 else if (ret_type == ANYCOMPATIBLERANGEOID || ret_type == ANYCOMPATIBLEMULTIRANGEOID)
2903 for (
int i = 0;
i < nargs;
i++)
2905 if (declared_arg_types[
i] == ANYCOMPATIBLERANGEOID ||
2906 declared_arg_types[
i] == ANYCOMPATIBLEMULTIRANGEOID)
2909 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatiblerange or anycompatiblemultirange."),
2912 else if (IsPolymorphicTypeFamily1(ret_type))
2915 for (
int i = 0;
i < nargs;
i++)
2917 if (IsPolymorphicTypeFamily1(declared_arg_types[
i]))
2921 return psprintf(
_(
"A result of type %s requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange."),
2924 else if (IsPolymorphicTypeFamily2(ret_type))
2927 for (
int i = 0;
i < nargs;
i++)
2929 if (IsPolymorphicTypeFamily2(declared_arg_types[
i]))
2933 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, anycompatiblerange, or anycompatiblemultirange."),
2953 const Oid *declared_arg_types,
2956 if (ret_type == INTERNALOID)
2958 for (
int i = 0;
i < nargs;
i++)
2960 if (declared_arg_types[
i] == ret_type)
2963 return pstrdup(
_(
"A result of type internal requires at least one input of type internal."));
2979 bool typispreferred;
2982 Assert(typcategory != TYPCATEGORY_INVALID);
2998 bool typispreferred;
3001 if (category == typcategory || category == TYPCATEGORY_INVALID)
3002 return typispreferred;
3055 if (srctype == targettype)
3059 if (targettype == ANYOID || targettype == ANYELEMENTOID ||
3060 targettype == ANYCOMPATIBLEOID)
3068 if (srctype == targettype)
3072 if (targettype == ANYARRAYOID || targettype == ANYCOMPATIBLEARRAYOID)
3077 if (targettype == ANYNONARRAYOID || targettype == ANYCOMPATIBLENONARRAYOID)
3082 if (targettype == ANYENUMOID)
3087 if (targettype == ANYRANGEOID || targettype == ANYCOMPATIBLERANGEOID)
3092 if (targettype == ANYMULTIRANGEOID || targettype == ANYCOMPATIBLEMULTIRANGEOID)
3097 if (targettype == RECORDOID)
3102 if (targettype == RECORDARRAYOID)
3114 result = (castForm->castmethod == COERCION_METHOD_BINARY &&
3115 castForm->castcontext == COERCION_CODE_IMPLICIT);
3118 *castoid = castForm->oid;
3169 if (sourceTypeId == targetTypeId)
3183 switch (castForm->castcontext)
3185 case COERCION_CODE_IMPLICIT:
3188 case COERCION_CODE_ASSIGNMENT:
3191 case COERCION_CODE_EXPLICIT:
3195 elog(
ERROR,
"unrecognized castcontext: %d",
3196 (
int) castForm->castcontext);
3202 if (ccontext >= castcontext)
3204 switch (castForm->castmethod)
3206 case COERCION_METHOD_FUNCTION:
3208 *funcid = castForm->castfunc;
3210 case COERCION_METHOD_INOUT:
3213 case COERCION_METHOD_BINARY:
3217 elog(
ERROR,
"unrecognized castmethod: %d",
3218 (
int) castForm->castmethod);
3239 if (targetTypeId != OIDVECTOROID && targetTypeId != INT2VECTOROID)
3331 if (IsTrueArrayType(typeForm))
3334 typeId = typeForm->typelem;
3348 *funcid = castForm->castfunc;
3383 bool result =
false;
3392 elog(
ERROR,
"cache lookup failed for relation %u", relid);
3395 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)
static void * GETSTRUCT(const HeapTupleData *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)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
RelabelType * makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
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)
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
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)
static Node * coerce_type_typmod(Node *node, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
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)
char * check_valid_internal_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
char * check_valid_polymorphic_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
Node * coerce_to_specific_type_typmod(ParseState *pstate, Node *node, Oid targetTypeId, int32 targetTypmod, const char *constructName)
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
int parser_coercion_errposition(ParseState *pstate, int coerce_location, Node *input_expr)
Node * coerce_null_to_domain(Oid typid, int32 typmod, Oid collation, int typlen, bool typbyval)
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)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
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)
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)
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
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)
List * expandNSItemVars(ParseState *pstate, ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
Oid typeOrDomainTypeRelid(Oid type_id)
Oid typeTypeCollation(Type typ)
char * typeTypeName(Type t)
Datum stringTypeDatum(Type tp, char *string, int32 atttypmod)
#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 * list_second_cell(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
FormData_pg_proc * Form_pg_proc
FormData_pg_type * Form_pg_type
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum 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)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)