29 #include "utils/fmgroids.h" 36 Oid targetTypeId,
int32 targetTypMod,
39 bool hideInputCoercion);
44 Oid targetTypeId,
int32 targetTypMod,
104 targettype, targettypmod,
105 ccontext, cformat, location);
113 targettype, targettypmod,
114 ccontext, cformat, location,
115 (result != expr && !
IsA(result,
Const)));
117 if (expr != origexpr)
123 newcoll->
arg = (
Expr *) result;
126 result = (
Node *) newcoll;
157 Oid inputTypeId,
Oid targetTypeId,
int32 targetTypeMod,
164 if (targetTypeId == inputTypeId ||
170 if (targetTypeId == ANYOID ||
171 targetTypeId == ANYELEMENTOID ||
172 targetTypeId == ANYNONARRAYOID ||
173 targetTypeId == ANYCOMPATIBLEOID ||
174 targetTypeId == ANYCOMPATIBLENONARRAYOID)
190 if (targetTypeId == ANYARRAYOID ||
191 targetTypeId == ANYENUMOID ||
192 targetTypeId == ANYRANGEOID ||
193 targetTypeId == ANYMULTIRANGEOID ||
194 targetTypeId == ANYCOMPATIBLEARRAYOID ||
195 targetTypeId == ANYCOMPATIBLERANGEOID ||
196 targetTypeId == ANYCOMPATIBLEMULTIRANGEOID)
213 if (inputTypeId != UNKNOWNOID)
217 if (baseTypeId != inputTypeId)
231 if (inputTypeId == UNKNOWNOID &&
IsA(node,
Const))
266 baseTypeMod = targetTypeMod;
278 if (baseTypeId == INTERVALOID)
279 inputTypeMod = baseTypeMod;
327 #ifdef RANDOMIZE_ALLOCATED_MEMORY 350 elog(
WARNING,
"type %s has unstable input conversion for \"%s\"",
357 result = (
Node *) newcon;
360 if (baseTypeId != targetTypeId)
362 baseTypeId, baseTypeMod,
364 ccontext, cformat, location,
400 inputTypeId, targetTypeId, targetTypeMod,
401 ccontext, cformat, location);
404 return (
Node *) newcoll;
422 baseTypeMod = targetTypeMod;
426 baseTypeId, baseTypeMod,
427 ccontext, cformat, location);
433 if (targetTypeId != baseTypeId)
436 ccontext, cformat, location,
451 ccontext, cformat, location,
472 if (inputTypeId == RECORDOID &&
477 ccontext, cformat, location);
479 if (targetTypeId == RECORDOID &&
487 if (inputTypeId == RECORDARRAYOID &&
494 if (targetTypeId == RECORDARRAYOID &&
518 if (baseTypeId != inputTypeId)
535 elog(
ERROR,
"failed to find conversion function from %s to %s",
552 bool have_generics =
false;
556 for (i = 0; i < nargs; i++)
558 Oid inputTypeId = input_typeids[
i];
559 Oid targetTypeId = target_typeids[
i];
564 if (inputTypeId == targetTypeId)
568 if (targetTypeId == ANYOID)
572 if (IsPolymorphicType(targetTypeId))
574 have_generics =
true;
582 if (inputTypeId == UNKNOWNOID)
598 if (inputTypeId == RECORDOID &&
605 if (targetTypeId == RECORDOID &&
615 if (inputTypeId == RECORDARRAYOID &&
623 if (targetTypeId == RECORDARRAYOID &&
671 bool hideInputCoercion)
680 if (baseTypeId == typeId)
684 if (hideInputCoercion)
717 return (
Node *) result;
749 bool hideInputCoercion)
758 if (targetTypMod < 0 || targetTypMod ==
exprTypmod(node))
766 if (hideInputCoercion)
770 targetTypeId, targetTypMod,
771 ccontext, cformat, location);
819 Oid targetTypeId,
int32 targetTypMod,
832 elog(
ERROR,
"cache lookup failed for function %u", funcId);
842 Assert(!procstruct->proretset);
843 Assert(procstruct->prokind == PROKIND_FUNCTION);
844 nargs = procstruct->pronargs;
845 Assert(nargs >= 1 && nargs <= 3);
847 Assert(nargs < 2 || procstruct->proargtypes.values[1] == INT4OID);
848 Assert(nargs < 3 || procstruct->proargtypes.values[2] == BOOLOID);
895 return (
Node *) fexpr;
902 Oid sourceBaseTypeId;
903 int32 sourceBaseTypeMod;
904 Oid targetElementType;
924 ctest->
typeMod = sourceBaseTypeMod;
939 if (elemexpr == NULL)
940 elog(
ERROR,
"failed to coerce array element type as expected");
955 return (
Node *) acoerce;
970 return (
Node *) iocoerce;
974 elog(
ERROR,
"unsupported pathtype %d in build_coercion_expression",
997 int32 baseTypeMod = -1;
1011 args = ((
RowExpr *) node)->args;
1013 else if (node &&
IsA(node,
Var) &&
1016 int rtindex = ((
Var *) node)->varno;
1017 int sublevels_up = ((
Var *) node)->varlevelsup;
1018 int vlocation = ((
Var *) node)->location;
1026 (
errcode(ERRCODE_CANNOT_COERCE),
1027 errmsg(
"cannot cast type %s to %s",
1043 for (i = 0; i < tupdesc->
natts; i++)
1051 if (attr->attisdropped)
1064 (
errcode(ERRCODE_CANNOT_COERCE),
1065 errmsg(
"cannot cast type %s to %s",
1068 errdetail(
"Input has too few columns."),
1082 (
errcode(ERRCODE_CANNOT_COERCE),
1083 errmsg(
"cannot cast type %s to %s",
1086 errdetail(
"Cannot cast type %s to %s in column %d.",
1091 newargs =
lappend(newargs, cexpr);
1093 arg =
lnext(args, arg);
1097 (
errcode(ERRCODE_CANNOT_COERCE),
1098 errmsg(
"cannot cast type %s to %s",
1101 errdetail(
"Input has too many columns."),
1107 rowexpr->
args = newargs;
1114 if (baseTypeId != targetTypeId)
1118 baseTypeId, baseTypeMod,
1120 ccontext, cformat, location,
1124 return (
Node *) rowexpr;
1139 const char *constructName)
1143 if (inputTypeId != BOOLOID)
1152 if (newnode == NULL)
1154 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1156 errmsg(
"argument of %s must be type %s, not type %s",
1157 constructName,
"boolean",
1165 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1167 errmsg(
"argument of %s must not return a set",
1186 Oid targetTypeId,
int32 targetTypmod,
1187 const char *constructName)
1191 if (inputTypeId != targetTypeId)
1196 targetTypeId, targetTypmod,
1200 if (newnode == NULL)
1202 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1204 errmsg(
"argument of %s must be type %s, not type %s",
1214 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1216 errmsg(
"argument of %s must not return a set",
1236 const char *constructName)
1255 int coerce_location,
1258 if (coerce_location >= 0)
1299 if (ptype != UNKNOWNOID)
1312 *which_expr = pexpr;
1331 if (ntype != UNKNOWNOID && ntype != ptype)
1337 if (ptype == UNKNOWNOID)
1342 pcategory = ncategory;
1343 pispreferred = nispreferred;
1345 else if (ncategory != pcategory)
1350 if (context == NULL)
1353 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1356 errmsg(
"%s types %s and %s cannot be matched",
1362 else if (!pispreferred &&
1372 pcategory = ncategory;
1373 pispreferred = nispreferred;
1389 if (ptype == UNKNOWNOID)
1393 *which_expr = pexpr;
1423 if (ptype != UNKNOWNOID)
1425 for (; i < nargs; i++)
1427 if (typeids[i] != ptype)
1441 for (; i < nargs; i++)
1446 if (ntype != UNKNOWNOID && ntype != ptype)
1452 if (ptype == UNKNOWNOID)
1456 pcategory = ncategory;
1457 pispreferred = nispreferred;
1459 else if (ncategory != pcategory)
1467 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1468 errmsg(
"argument types %s and %s cannot be matched",
1472 else if (!pispreferred &&
1481 pcategory = ncategory;
1482 pispreferred = nispreferred;
1488 if (ptype == UNKNOWNOID)
1507 Oid targetTypeId,
const char *context)
1511 if (inputTypeId == targetTypeId)
1514 node =
coerce_type(pstate, node, inputTypeId, targetTypeId, -1,
1518 (
errcode(ERRCODE_CANNOT_COERCE),
1520 errmsg(
"%s could not convert type %s to %s",
1626 const Oid *declared_arg_types,
1638 bool have_anynonarray =
false;
1639 bool have_anyenum =
false;
1640 bool have_anycompatible_nonarray =
false;
1641 int n_anycompatible_args = 0;
1649 for (
int j = 0; j < nargs; j++)
1651 Oid decl_type = declared_arg_types[j];
1652 Oid actual_type = actual_arg_types[j];
1654 if (decl_type == ANYELEMENTOID ||
1655 decl_type == ANYNONARRAYOID ||
1656 decl_type == ANYENUMOID)
1658 if (decl_type == ANYNONARRAYOID)
1659 have_anynonarray =
true;
1660 else if (decl_type == ANYENUMOID)
1661 have_anyenum =
true;
1662 if (actual_type == UNKNOWNOID)
1664 if (
OidIsValid(elem_typeid) && actual_type != elem_typeid)
1666 elem_typeid = actual_type;
1668 else if (decl_type == ANYARRAYOID)
1670 if (actual_type == UNKNOWNOID)
1673 if (
OidIsValid(array_typeid) && actual_type != array_typeid)
1675 array_typeid = actual_type;
1677 else if (decl_type == ANYRANGEOID)
1679 if (actual_type == UNKNOWNOID)
1682 if (
OidIsValid(range_typeid) && actual_type != range_typeid)
1684 range_typeid = actual_type;
1686 else if (decl_type == ANYMULTIRANGEOID)
1688 if (actual_type == UNKNOWNOID)
1691 if (
OidIsValid(multirange_typeid) && actual_type != multirange_typeid)
1693 multirange_typeid = actual_type;
1695 else if (decl_type == ANYCOMPATIBLEOID ||
1696 decl_type == ANYCOMPATIBLENONARRAYOID)
1698 if (decl_type == ANYCOMPATIBLENONARRAYOID)
1699 have_anycompatible_nonarray =
true;
1700 if (actual_type == UNKNOWNOID)
1703 anycompatible_actual_types[n_anycompatible_args++] = actual_type;
1705 else if (decl_type == ANYCOMPATIBLEARRAYOID)
1709 if (actual_type == UNKNOWNOID)
1716 anycompatible_actual_types[n_anycompatible_args++] = elem_type;
1718 else if (decl_type == ANYCOMPATIBLERANGEOID)
1720 if (actual_type == UNKNOWNOID)
1726 if (anycompatible_range_typeid != actual_type)
1731 anycompatible_range_typeid = actual_type;
1733 if (!
OidIsValid(anycompatible_range_typelem))
1736 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
1739 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
1741 if (actual_type == UNKNOWNOID)
1744 if (
OidIsValid(anycompatible_multirange_typeid))
1747 if (anycompatible_multirange_typeid != actual_type)
1752 anycompatible_multirange_typeid = actual_type;
1754 if (!
OidIsValid(anycompatible_multirange_typelem))
1763 if (anycompatible_range_typeid != anycompatible_multirange_typelem)
1768 anycompatible_range_typeid = anycompatible_multirange_typelem;
1770 if (!
OidIsValid(anycompatible_range_typelem))
1774 anycompatible_actual_types[n_anycompatible_args++] =
1775 anycompatible_range_typelem;
1783 if (array_typeid == ANYARRAYOID)
1811 elem_typeid = array_typelem;
1813 else if (array_typelem != elem_typeid)
1833 elem_typeid = range_typelem;
1835 else if (range_typelem != elem_typeid)
1845 Oid multirange_typelem;
1856 range_typeid = multirange_typelem;
1861 else if (multirange_typelem != range_typeid)
1872 elem_typeid = range_typelem;
1874 else if (range_typelem != elem_typeid)
1881 if (have_anynonarray)
1896 if (n_anycompatible_args > 0)
1898 Oid anycompatible_typeid;
1900 anycompatible_typeid =
1902 anycompatible_actual_types,
1908 if (have_anycompatible_nonarray)
1924 if (
OidIsValid(anycompatible_range_typelem) &&
1925 anycompatible_range_typelem != anycompatible_typeid)
2025 Oid *declared_arg_types,
2030 bool have_poly_anycompatible =
false;
2031 bool have_poly_unknowns =
false;
2043 Oid multirange_typelem;
2044 bool have_anynonarray = (rettype == ANYNONARRAYOID);
2045 bool have_anyenum = (rettype == ANYENUMOID);
2046 bool have_anycompatible_nonarray = (rettype == ANYCOMPATIBLENONARRAYOID);
2047 bool have_anycompatible_array = (rettype == ANYCOMPATIBLEARRAYOID);
2048 bool have_anycompatible_range = (rettype == ANYCOMPATIBLERANGEOID);
2049 int n_poly_args = 0;
2050 int n_anycompatible_args = 0;
2058 for (
int j = 0; j < nargs; j++)
2060 Oid decl_type = declared_arg_types[j];
2061 Oid actual_type = actual_arg_types[j];
2063 if (decl_type == ANYELEMENTOID ||
2064 decl_type == ANYNONARRAYOID ||
2065 decl_type == ANYENUMOID)
2068 if (decl_type == ANYNONARRAYOID)
2069 have_anynonarray =
true;
2070 else if (decl_type == ANYENUMOID)
2071 have_anyenum =
true;
2072 if (actual_type == UNKNOWNOID)
2074 have_poly_unknowns =
true;
2077 if (allow_poly && decl_type == actual_type)
2079 if (
OidIsValid(elem_typeid) && actual_type != elem_typeid)
2081 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2082 errmsg(
"arguments declared \"anyelement\" are not all alike"),
2086 elem_typeid = actual_type;
2088 else if (decl_type == ANYARRAYOID)
2091 if (actual_type == UNKNOWNOID)
2093 have_poly_unknowns =
true;
2096 if (allow_poly && decl_type == actual_type)
2099 if (
OidIsValid(array_typeid) && actual_type != array_typeid)
2101 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2102 errmsg(
"arguments declared \"anyarray\" are not all alike"),
2106 array_typeid = actual_type;
2108 else if (decl_type == ANYRANGEOID)
2111 if (actual_type == UNKNOWNOID)
2113 have_poly_unknowns =
true;
2116 if (allow_poly && decl_type == actual_type)
2119 if (
OidIsValid(range_typeid) && actual_type != range_typeid)
2121 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2122 errmsg(
"arguments declared \"anyrange\" are not all alike"),
2126 range_typeid = actual_type;
2128 else if (decl_type == ANYMULTIRANGEOID)
2131 if (actual_type == UNKNOWNOID)
2133 have_poly_unknowns =
true;
2136 if (allow_poly && decl_type == actual_type)
2139 if (
OidIsValid(multirange_typeid) && actual_type != multirange_typeid)
2141 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2142 errmsg(
"arguments declared \"anymultirange\" are not all alike"),
2146 multirange_typeid = actual_type;
2148 else if (decl_type == ANYCOMPATIBLEOID ||
2149 decl_type == ANYCOMPATIBLENONARRAYOID)
2151 have_poly_anycompatible =
true;
2152 if (decl_type == ANYCOMPATIBLENONARRAYOID)
2153 have_anycompatible_nonarray =
true;
2154 if (actual_type == UNKNOWNOID)
2156 if (allow_poly && decl_type == actual_type)
2159 anycompatible_actual_types[n_anycompatible_args++] = actual_type;
2161 else if (decl_type == ANYCOMPATIBLEARRAYOID)
2163 Oid anycompatible_elem_type;
2165 have_poly_anycompatible =
true;
2166 have_anycompatible_array =
true;
2167 if (actual_type == UNKNOWNOID)
2169 if (allow_poly && decl_type == actual_type)
2175 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2176 errmsg(
"argument declared %s is not an array but type %s",
2177 "anycompatiblearray",
2180 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_elem_type;
2182 else if (decl_type == ANYCOMPATIBLERANGEOID)
2184 have_poly_anycompatible =
true;
2185 have_anycompatible_range =
true;
2186 if (actual_type == UNKNOWNOID)
2188 if (allow_poly && decl_type == actual_type)
2194 if (anycompatible_range_typeid != actual_type)
2196 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2197 errmsg(
"arguments declared \"anycompatiblerange\" are not all alike"),
2204 anycompatible_range_typeid = actual_type;
2206 if (!
OidIsValid(anycompatible_range_typelem))
2208 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2209 errmsg(
"argument declared %s is not a range type but type %s",
2210 "anycompatiblerange",
2213 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
2216 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
2218 have_poly_anycompatible =
true;
2219 if (actual_type == UNKNOWNOID)
2221 if (allow_poly && decl_type == actual_type)
2224 if (
OidIsValid(anycompatible_multirange_typeid))
2227 if (anycompatible_multirange_typeid != actual_type)
2229 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2230 errmsg(
"arguments declared \"anycompatiblemultirange\" are not all alike"),
2237 anycompatible_multirange_typeid = actual_type;
2239 anycompatible_range_typelem =
get_range_subtype(anycompatible_multirange_typelem);
2240 if (!
OidIsValid(anycompatible_multirange_typelem))
2242 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2243 errmsg(
"argument declared %s is not a multirange type but type %s",
2244 "anycompatiblemultirange",
2247 anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
2256 if (n_poly_args == 0 && !have_poly_anycompatible)
2267 if (array_typeid == ANYARRAYOID)
2276 if (n_poly_args != 1 ||
2277 (rettype != ANYARRAYOID &&
2278 IsPolymorphicTypeFamily1(rettype)))
2280 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2281 errmsg(
"cannot determine element type of \"anyarray\" argument")));
2282 array_typelem = ANYELEMENTOID;
2289 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2290 errmsg(
"argument declared %s is not an array but type %s",
2300 elem_typeid = array_typelem;
2302 else if (array_typelem != elem_typeid)
2306 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2307 errmsg(
"argument declared %s is not consistent with argument declared %s",
2308 "anyarray",
"anyelement"),
2321 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2322 errmsg(
"argument declared %s is not a range type but type %s",
2332 elem_typeid = range_typelem;
2334 else if (range_typelem != elem_typeid)
2338 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2339 errmsg(
"argument declared %s is not consistent with argument declared %s",
2340 "anyrange",
"anyelement"),
2355 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2356 errmsg(
"argument declared %s is not a multirange type but type %s",
2365 range_typeid = multirange_typelem;
2368 else if (multirange_typelem != range_typeid)
2372 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2373 errmsg(
"argument declared %s is not consistent with argument declared %s",
2374 "anymultirange",
"anyrange"),
2386 elem_typeid = range_typelem;
2388 else if (range_typelem != elem_typeid)
2392 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2393 errmsg(
"argument declared %s is not consistent with argument declared %s",
2394 "anymultirange",
"anyelement"),
2407 elem_typeid = ANYELEMENTOID;
2408 array_typeid = ANYARRAYOID;
2409 range_typeid = ANYRANGEOID;
2410 multirange_typeid = ANYMULTIRANGEOID;
2419 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2420 errmsg(
"could not determine polymorphic type because input has type %s",
2425 if (have_anynonarray && elem_typeid != ANYELEMENTOID)
2433 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2434 errmsg(
"type matched to anynonarray is an array type: %s",
2438 if (have_anyenum && elem_typeid != ANYELEMENTOID)
2443 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2444 errmsg(
"type matched to anyenum is not an enum type: %s",
2450 if (have_poly_anycompatible)
2452 if (n_anycompatible_args > 0)
2454 anycompatible_typeid =
2456 anycompatible_actual_types,
2459 if (have_anycompatible_array)
2461 anycompatible_array_typeid =
get_array_type(anycompatible_typeid);
2464 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2465 errmsg(
"could not find array type for data type %s",
2469 if (have_anycompatible_range)
2474 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2475 errmsg(
"could not determine polymorphic type %s because input has type %s",
2476 "anycompatiblerange",
"unknown")));
2482 if (anycompatible_range_typelem != anycompatible_typeid)
2484 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2485 errmsg(
"anycompatiblerange type %s does not match anycompatible type %s",
2490 if (have_anycompatible_nonarray)
2498 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2499 errmsg(
"type matched to anycompatiblenonarray is an array type: %s",
2507 anycompatible_typeid = ANYCOMPATIBLEOID;
2508 anycompatible_array_typeid = ANYCOMPATIBLEARRAYOID;
2509 anycompatible_range_typeid = ANYCOMPATIBLERANGEOID;
2510 anycompatible_multirange_typeid = ANYCOMPATIBLEMULTIRANGEOID;
2520 anycompatible_typeid = TEXTOID;
2521 anycompatible_array_typeid = TEXTARRAYOID;
2522 if (have_anycompatible_range)
2524 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2525 errmsg(
"could not determine polymorphic type %s because input has type %s",
2526 "anycompatiblerange",
"unknown")));
2531 for (
int j = 0; j < nargs; j++)
2533 Oid decl_type = declared_arg_types[j];
2535 if (decl_type == ANYCOMPATIBLEOID ||
2536 decl_type == ANYCOMPATIBLENONARRAYOID)
2537 declared_arg_types[j] = anycompatible_typeid;
2538 else if (decl_type == ANYCOMPATIBLEARRAYOID)
2539 declared_arg_types[j] = anycompatible_array_typeid;
2540 else if (decl_type == ANYCOMPATIBLERANGEOID)
2541 declared_arg_types[j] = anycompatible_range_typeid;
2542 else if (decl_type == ANYCOMPATIBLEMULTIRANGEOID)
2543 declared_arg_types[j] = anycompatible_multirange_typeid;
2555 if (have_poly_unknowns)
2557 for (
int j = 0; j < nargs; j++)
2559 Oid decl_type = declared_arg_types[j];
2560 Oid actual_type = actual_arg_types[j];
2562 if (actual_type != UNKNOWNOID)
2565 if (decl_type == ANYELEMENTOID ||
2566 decl_type == ANYNONARRAYOID ||
2567 decl_type == ANYENUMOID)
2568 declared_arg_types[j] = elem_typeid;
2569 else if (decl_type == ANYARRAYOID)
2576 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2577 errmsg(
"could not find array type for data type %s",
2580 declared_arg_types[j] = array_typeid;
2582 else if (decl_type == ANYRANGEOID)
2588 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2589 errmsg(
"could not determine polymorphic type %s because input has type %s",
2590 "anyrange",
"unknown")));
2592 declared_arg_types[j] = range_typeid;
2594 else if (decl_type == ANYMULTIRANGEOID)
2599 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2600 errmsg(
"could not find multirange type for data type %s",
2603 declared_arg_types[j] = multirange_typeid;
2609 if (rettype == ANYELEMENTOID ||
2610 rettype == ANYNONARRAYOID ||
2611 rettype == ANYENUMOID)
2615 if (rettype == ANYARRAYOID)
2622 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2623 errmsg(
"could not find array type for data type %s",
2626 return array_typeid;
2630 if (rettype == ANYRANGEOID)
2635 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2636 errmsg(
"could not determine polymorphic type %s because input has type %s",
2637 "anyrange",
"unknown")));
2638 return range_typeid;
2642 if (rettype == ANYMULTIRANGEOID)
2650 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2651 errmsg(
"could not find multirange type for data type %s",
2654 return multirange_typeid;
2658 if (rettype == ANYCOMPATIBLEOID ||
2659 rettype == ANYCOMPATIBLENONARRAYOID)
2664 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2666 return anycompatible_typeid;
2670 if (rettype == ANYCOMPATIBLEARRAYOID)
2675 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2677 return anycompatible_array_typeid;
2681 if (rettype == ANYCOMPATIBLERANGEOID)
2686 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2688 return anycompatible_range_typeid;
2692 if (rettype == ANYCOMPATIBLEMULTIRANGEOID)
2695 if (!
OidIsValid(anycompatible_multirange_typeid))
2697 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2699 return anycompatible_multirange_typeid;
2716 const Oid *declared_arg_types,
2719 if (ret_type == ANYRANGEOID || ret_type == ANYMULTIRANGEOID)
2726 for (
int i = 0;
i < nargs;
i++)
2728 if (declared_arg_types[
i] == ANYRANGEOID ||
2729 declared_arg_types[
i] == ANYMULTIRANGEOID)
2732 return psprintf(
_(
"A result of type %s requires at least one input of type anyrange or anymultirange."),
2735 else if (ret_type == ANYCOMPATIBLERANGEOID || ret_type == ANYCOMPATIBLEMULTIRANGEOID)
2743 for (
int i = 0;
i < nargs;
i++)
2745 if (declared_arg_types[
i] == ANYCOMPATIBLERANGEOID ||
2746 declared_arg_types[
i] == ANYCOMPATIBLEMULTIRANGEOID)
2749 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatiblerange or anycompatiblemultirange."),
2752 else if (IsPolymorphicTypeFamily1(ret_type))
2755 for (
int i = 0;
i < nargs;
i++)
2757 if (IsPolymorphicTypeFamily1(declared_arg_types[
i]))
2761 return psprintf(
_(
"A result of type %s requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange."),
2764 else if (IsPolymorphicTypeFamily2(ret_type))
2767 for (
int i = 0;
i < nargs;
i++)
2769 if (IsPolymorphicTypeFamily2(declared_arg_types[
i]))
2773 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, or anycompatiblerange."),
2793 const Oid *declared_arg_types,
2796 if (ret_type == INTERNALOID)
2798 for (
int i = 0;
i < nargs;
i++)
2800 if (declared_arg_types[
i] == ret_type)
2803 return pstrdup(
_(
"A result of type internal requires at least one input of type internal."));
2819 bool typispreferred;
2822 Assert(typcategory != TYPCATEGORY_INVALID);
2838 bool typispreferred;
2841 if (category == typcategory || category == TYPCATEGORY_INVALID)
2842 return typispreferred;
2877 if (srctype == targettype)
2881 if (targettype == ANYOID || targettype == ANYELEMENTOID ||
2882 targettype == ANYCOMPATIBLEOID)
2890 if (srctype == targettype)
2894 if (targettype == ANYARRAYOID || targettype == ANYCOMPATIBLEARRAYOID)
2899 if (targettype == ANYNONARRAYOID || targettype == ANYCOMPATIBLENONARRAYOID)
2904 if (targettype == ANYENUMOID)
2909 if (targettype == ANYRANGEOID || targettype == ANYCOMPATIBLERANGEOID)
2914 if (targettype == ANYMULTIRANGEOID || targettype == ANYCOMPATIBLEMULTIRANGEOID)
2919 if (targettype == RECORDOID)
2924 if (targettype == RECORDARRAYOID)
2936 result = (castForm->castmethod == COERCION_METHOD_BINARY &&
2937 castForm->castcontext == COERCION_CODE_IMPLICIT);
2988 if (sourceTypeId == targetTypeId)
3002 switch (castForm->castcontext)
3004 case COERCION_CODE_IMPLICIT:
3007 case COERCION_CODE_ASSIGNMENT:
3010 case COERCION_CODE_EXPLICIT:
3014 elog(
ERROR,
"unrecognized castcontext: %d",
3015 (
int) castForm->castcontext);
3021 if (ccontext >= castcontext)
3023 switch (castForm->castmethod)
3025 case COERCION_METHOD_FUNCTION:
3027 *funcid = castForm->castfunc;
3029 case COERCION_METHOD_INOUT:
3032 case COERCION_METHOD_BINARY:
3036 elog(
ERROR,
"unrecognized castmethod: %d",
3037 (
int) castForm->castmethod);
3058 if (targetTypeId != OIDVECTOROID && targetTypeId != INT2VECTOROID)
3150 if (IsTrueArrayType(typeForm))
3153 typeId = typeForm->typelem;
3167 *funcid = castForm->castfunc;
3202 bool result =
false;
3211 elog(
ERROR,
"cache lookup failed for relation %u", relid);
3214 if (reltup->reloftype == reloftypeId)
bool check_generic_type_consistency(const Oid *actual_arg_types, const Oid *declared_arg_types, int nargs)
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Oid typeTypeCollation(Type typ)
#define IsA(nodeptr, _type_)
Oid enforce_generic_type_consistency(const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
#define type_is_array_domain(typid)
Oid typeOrDomainTypeRelid(Oid type_id)
int exprLocation(const Node *expr)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
char * check_valid_polymorphic_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
static ListCell * lnext(const List *l, const ListCell *c)
int32 exprTypmod(const Node *expr)
Oid get_element_type(Oid typid)
#define PointerGetDatum(X)
#define TupleDescAttr(tupdesc, i)
Oid get_array_type(Oid typid)
#define for_each_cell(cell, lst, initcell)
int32 select_common_typmod(ParseState *pstate, List *exprs, Oid common_type)
char * pstrdup(const char *in)
char * psprintf(const char *fmt,...)
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
bool expression_returns_set(Node *clause)
bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
CoerceParamHook p_coerce_param_hook
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
CoercionForm coercionformat
int errcode(int sqlerrcode)
bool type_is_range(Oid typid)
Oid get_range_multirange(Oid rangeOid)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
#define OidIsValid(objectId)
bool IsPreferredType(TYPCATEGORY category, Oid type)
static Oid select_common_type_from_oids(int nargs, const Oid *typeids, bool noerror)
Oid get_multirange_range(Oid multirangeOid)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
static void hide_coercion_node(Node *node)
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
#define ObjectIdGetDatum(X)
#define DatumGetCString(X)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
char * typeTypeName(Type t)
Datum stringTypeDatum(Type tp, char *string, int32 atttypmod)
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
RelabelType * makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
static ListCell * list_second_cell(const List *l)
int errdetail(const char *fmt,...)
static Node * build_coercion_expression(Node *node, CoercionPathType pathtype, Oid funcId, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location)
static ListCell * list_head(const List *l)
FormData_pg_attribute * Form_pg_attribute
static Node * coerce_type_typmod(Node *node, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
FormData_pg_cast * Form_pg_cast
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Node * coerce_to_common_type(ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
CoercionPathType find_typmod_coercion_function(Oid typeId, Oid *funcid)
List * lappend(List *list, void *datum)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
CoercionForm coerceformat
CoercionForm convertformat
void ReleaseSysCache(HeapTuple tuple)
FormData_pg_proc * Form_pg_proc
TYPCATEGORY TypeCategory(Oid type)
#define ereport(elevel,...)
int errmsg_internal(const char *fmt,...)
#define HeapTupleIsValid(tuple)
#define Assert(condition)
char * check_valid_internal_signature(Oid ret_type, const Oid *declared_arg_types, int nargs)
bool typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
List * expandNSItemVars(ParseNamespaceItem *nsitem, int sublevels_up, int location, List **colnames)
#define ISCOMPLEX(typeid)
static bool typeIsOfTypedTable(Oid reltypeId, Oid reloftypeId)
bool type_is_multirange(Oid typid)
bool type_is_enum(Oid typid)
Oid exprType(const Node *expr)
FormData_pg_type * Form_pg_type
int parser_errposition(ParseState *pstate, int location)
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
#define type_is_array(typid)
#define InvalidAttrNumber
static Node * coerce_record_to_complex(ParseState *pstate, Node *node, Oid targetTypeId, CoercionContext ccontext, CoercionForm cformat, int location)
CoercionForm coerceformat
FormData_pg_class * Form_pg_class
ParseNamespaceItem * GetNSItemByRangeTablePosn(ParseState *pstate, int varno, int sublevels_up)
int errmsg(const char *fmt,...)
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_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)
#define PG_DETOAST_DATUM(datum)
static bool is_complex_array(Oid typid)
#define ReleaseTupleDesc(tupdesc)
Oid getBaseType(Oid typid)
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
Node * coerce_to_specific_type_typmod(ParseState *pstate, Node *node, Oid targetTypeId, int32 targetTypmod, const char *constructName)
Oid get_range_subtype(Oid rangeOid)
FuncExpr * makeFuncExpr(Oid funcid, Oid rettype, List *args, Oid funccollid, Oid inputcollid, CoercionForm fformat)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)