30#include "utils/fmgroids.h"
106 targettype, targettypmod,
115 targettype, targettypmod,
117 (result != expr && !
IsA(result,
Const)));
292 newcon->constisnull = con->constisnull;
299 newcon->location = con->location;
311 if (!con->constisnull)
325 if (!con->constisnull &&
newcon->constlen == -1)
329#ifdef RANDOMIZE_ALLOCATED_MEMORY
342 if (!con->constisnull && !
newcon->constbyval)
349 if (
newcon->constlen == -1)
352 elog(
WARNING,
"type %s has unstable input conversion for \"%s\"",
534 rt->location = location;
544 elog(
ERROR,
"failed to find conversion function from %s to %s",
565 for (
i = 0;
i < nargs;
i++)
718 result->resulttypmod = -1;
720 result->coercionformat =
cformat;
723 return (
Node *) result;
867 Assert(nargs >= 1 && nargs <= 3);
916 fexpr->location = location;
961 if (elemexpr ==
NULL)
962 elog(
ERROR,
"failed to coerce array element type as expected");
989 iocoerce->coerceformat =
cformat;
992 return (
Node *) iocoerce;
996 elog(
ERROR,
"unsupported pathtype %d in build_coercion_expression",
1033 args = ((
RowExpr *) node)->args;
1035 else if (node &&
IsA(node,
Var) &&
1038 int rtindex = ((
Var *) node)->varno;
1039 int sublevels_up = ((
Var *) node)->varlevelsup;
1049 errmsg(
"cannot cast type %s to %s",
1065 for (
i = 0;
i < tupdesc->
natts;
i++)
1073 if (attr->attisdropped)
1087 errmsg(
"cannot cast type %s to %s",
1090 errdetail(
"Input has too few columns."),
1105 errmsg(
"cannot cast type %s to %s",
1108 errdetail(
"Cannot cast type %s to %s in column %d.",
1120 errmsg(
"cannot cast type %s to %s",
1123 errdetail(
"Input has too many columns."),
1131 rowexpr->row_format =
cformat;
1132 rowexpr->colnames =
NIL;
1146 return (
Node *) rowexpr;
1178 errmsg(
"argument of %s must be type %s, not type %s",
1189 errmsg(
"argument of %s must not return a set",
1226 errmsg(
"argument of %s must be type %s, not type %s",
1238 errmsg(
"argument of %s must not return a set",
1273 int typlen,
bool typbyval)
1413 if (context ==
NULL)
1419 errmsg(
"%s types %s and %s cannot be matched",
1492 for (;
i < nargs;
i++)
1508 for (;
i < nargs;
i++)
1535 errmsg(
"argument types %s and %s cannot be matched",
1587 errmsg(
"%s could not convert type %s to %s",
1629 for (
int i = 0;
i < nargs;
i++)
1762 for (
int j = 0;
j < nargs;
j++)
2166 for (
int j = 0;
j < nargs;
j++)
2190 errmsg(
"arguments declared \"%s\" are not all alike",
"anyelement"),
2210 errmsg(
"arguments declared \"%s\" are not all alike",
"anyarray"),
2230 errmsg(
"arguments declared \"%s\" are not all alike",
"anyrange"),
2251 errmsg(
"arguments declared \"%s\" are not all alike",
"anymultirange"),
2285 errmsg(
"argument declared %s is not an array but type %s",
2286 "anycompatiblearray",
2306 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblerange"),
2318 errmsg(
"argument declared %s is not a range type but type %s",
2319 "anycompatiblerange",
2340 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblemultirange"),
2352 errmsg(
"argument declared %s is not a multirange type but type %s",
2353 "anycompatiblemultirange",
2389 errmsg(
"cannot determine element type of \"anyarray\" argument")));
2398 errmsg(
"argument declared %s is not an array but type %s",
2415 errmsg(
"argument declared %s is not consistent with argument declared %s",
2416 "anyarray",
"anyelement"),
2432 errmsg(
"argument declared %s is not a multirange type but type %s",
2446 errmsg(
"argument declared %s is not consistent with argument declared %s",
2447 "anymultirange",
"anyrange"),
2468 errmsg(
"argument declared %s is not a range type but type %s",
2485 errmsg(
"argument declared %s is not consistent with argument declared %s",
2486 "anyrange",
"anyelement"),
2510 errmsg(
"could not determine polymorphic type because input has type %s",
2524 errmsg(
"type matched to anynonarray is an array type: %s",
2534 errmsg(
"type matched to anyenum is not an enum type: %s",
2551 errmsg(
"argument declared %s is not consistent with argument declared %s",
2552 "anycompatiblemultirange",
2553 "anycompatiblerange"),
2565 errmsg(
"argument declared %s is not a multirange type but type %s",
2566 "anycompatiblemultirange",
2595 errmsg(
"arguments of anycompatible family cannot be cast to a common type")));
2603 errmsg(
"could not find array type for data type %s",
2613 errmsg(
"could not determine polymorphic type %s because input has type %s",
2614 "anycompatiblerange",
"unknown")));
2623 errmsg(
"anycompatiblerange type %s does not match anycompatible type %s",
2634 errmsg(
"could not determine polymorphic type %s because input has type %s",
2635 "anycompatiblemultirange",
"unknown")));
2644 errmsg(
"anycompatiblemultirange type %s does not match anycompatible type %s",
2658 errmsg(
"type matched to anycompatiblenonarray is an array type: %s",
2684 errmsg(
"could not determine polymorphic type %s because input has type %s",
2685 "anycompatiblerange",
"unknown")));
2689 errmsg(
"could not determine polymorphic type %s because input has type %s",
2690 "anycompatiblemultirange",
"unknown")));
2695 for (
int j = 0;
j < nargs;
j++)
2721 for (
int j = 0;
j < nargs;
j++)
2741 errmsg(
"could not find array type for data type %s",
2753 errmsg(
"could not determine polymorphic type %s because input has type %s",
2754 "anyrange",
"unknown")));
2765 errmsg(
"could not determine polymorphic type %s because input has type %s",
2766 "anymultirange",
"unknown")));
2788 errmsg(
"could not find array type for data type %s",
2801 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2802 "anyrange",
"unknown")));
2813 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2814 "anymultirange",
"unknown")));
2887 for (
int i = 0;
i < nargs;
i++)
2893 return psprintf(
_(
"A result of type %s requires at least one input of type anyrange or anymultirange."),
2904 for (
int i = 0;
i < nargs;
i++)
2910 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatiblerange or anycompatiblemultirange."),
2916 for (
int i = 0;
i < nargs;
i++)
2922 return psprintf(
_(
"A result of type %s requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange."),
2928 for (
int i = 0;
i < nargs;
i++)
2934 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, anycompatiblerange, or anycompatiblemultirange."),
2959 for (
int i = 0;
i < nargs;
i++)
2964 return pstrdup(
_(
"A result of type internal requires at least one input of type internal."));
3056 if (srctype == targettype)
3069 if (srctype == targettype)
3196 elog(
ERROR,
"unrecognized castcontext: %d",
3218 elog(
ERROR,
"unrecognized castmethod: %d",
3384 bool result =
false;
3393 elog(
ERROR,
"cache lookup failed for relation %u", relid);
#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)