30#include "utils/fmgroids.h"
106 targettype, targettypmod,
115 targettype, targettypmod,
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++)
717 result->resulttype = typeId;
718 result->resulttypmod = -1;
721 result->location = location;
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) &&
1048 errmsg(
"cannot cast type %s to %s",
1064 for (
i = 0;
i < tupdesc->
natts;
i++)
1072 if (attr->attisdropped)
1086 errmsg(
"cannot cast type %s to %s",
1089 errdetail(
"Input has too few columns."),
1104 errmsg(
"cannot cast type %s to %s",
1107 errdetail(
"Cannot cast type %s to %s in column %d.",
1119 errmsg(
"cannot cast type %s to %s",
1122 errdetail(
"Input has too many columns."),
1130 rowexpr->row_format =
cformat;
1131 rowexpr->colnames =
NIL;
1145 return (
Node *) rowexpr;
1177 errmsg(
"argument of %s must be type %s, not type %s",
1188 errmsg(
"argument of %s must not return a set",
1225 errmsg(
"argument of %s must be type %s, not type %s",
1237 errmsg(
"argument of %s must not return a set",
1272 int typlen,
bool typbyval)
1412 if (context ==
NULL)
1418 errmsg(
"%s types %s and %s cannot be matched",
1491 for (;
i < nargs;
i++)
1507 for (;
i < nargs;
i++)
1534 errmsg(
"argument types %s and %s cannot be matched",
1586 errmsg(
"%s could not convert type %s to %s",
1628 for (
int i = 0;
i < nargs;
i++)
1761 for (
int j = 0;
j < nargs;
j++)
2165 for (
int j = 0;
j < nargs;
j++)
2189 errmsg(
"arguments declared \"%s\" are not all alike",
"anyelement"),
2209 errmsg(
"arguments declared \"%s\" are not all alike",
"anyarray"),
2229 errmsg(
"arguments declared \"%s\" are not all alike",
"anyrange"),
2250 errmsg(
"arguments declared \"%s\" are not all alike",
"anymultirange"),
2284 errmsg(
"argument declared %s is not an array but type %s",
2285 "anycompatiblearray",
2305 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblerange"),
2317 errmsg(
"argument declared %s is not a range type but type %s",
2318 "anycompatiblerange",
2339 errmsg(
"arguments declared \"%s\" are not all alike",
"anycompatiblemultirange"),
2351 errmsg(
"argument declared %s is not a multirange type but type %s",
2352 "anycompatiblemultirange",
2388 errmsg(
"cannot determine element type of \"anyarray\" argument")));
2397 errmsg(
"argument declared %s is not an array but type %s",
2414 errmsg(
"argument declared %s is not consistent with argument declared %s",
2415 "anyarray",
"anyelement"),
2431 errmsg(
"argument declared %s is not a multirange type but type %s",
2445 errmsg(
"argument declared %s is not consistent with argument declared %s",
2446 "anymultirange",
"anyrange"),
2467 errmsg(
"argument declared %s is not a range type but type %s",
2484 errmsg(
"argument declared %s is not consistent with argument declared %s",
2485 "anyrange",
"anyelement"),
2509 errmsg(
"could not determine polymorphic type because input has type %s",
2523 errmsg(
"type matched to anynonarray is an array type: %s",
2533 errmsg(
"type matched to anyenum is not an enum type: %s",
2550 errmsg(
"argument declared %s is not consistent with argument declared %s",
2551 "anycompatiblemultirange",
2552 "anycompatiblerange"),
2564 errmsg(
"argument declared %s is not a multirange type but type %s",
2565 "anycompatiblemultirange",
2594 errmsg(
"arguments of anycompatible family cannot be cast to a common type")));
2602 errmsg(
"could not find array type for data type %s",
2612 errmsg(
"could not determine polymorphic type %s because input has type %s",
2613 "anycompatiblerange",
"unknown")));
2622 errmsg(
"anycompatiblerange type %s does not match anycompatible type %s",
2633 errmsg(
"could not determine polymorphic type %s because input has type %s",
2634 "anycompatiblemultirange",
"unknown")));
2643 errmsg(
"anycompatiblemultirange type %s does not match anycompatible type %s",
2657 errmsg(
"type matched to anycompatiblenonarray is an array type: %s",
2683 errmsg(
"could not determine polymorphic type %s because input has type %s",
2684 "anycompatiblerange",
"unknown")));
2688 errmsg(
"could not determine polymorphic type %s because input has type %s",
2689 "anycompatiblemultirange",
"unknown")));
2694 for (
int j = 0;
j < nargs;
j++)
2720 for (
int j = 0;
j < nargs;
j++)
2740 errmsg(
"could not find array type for data type %s",
2752 errmsg(
"could not determine polymorphic type %s because input has type %s",
2753 "anyrange",
"unknown")));
2764 errmsg(
"could not determine polymorphic type %s because input has type %s",
2765 "anymultirange",
"unknown")));
2787 errmsg(
"could not find array type for data type %s",
2800 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2801 "anyrange",
"unknown")));
2812 errmsg_internal(
"could not determine polymorphic type %s because input has type %s",
2813 "anymultirange",
"unknown")));
2886 for (
int i = 0;
i < nargs;
i++)
2892 return psprintf(
_(
"A result of type %s requires at least one input of type anyrange or anymultirange."),
2903 for (
int i = 0;
i < nargs;
i++)
2909 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatiblerange or anycompatiblemultirange."),
2915 for (
int i = 0;
i < nargs;
i++)
2921 return psprintf(
_(
"A result of type %s requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange."),
2927 for (
int i = 0;
i < nargs;
i++)
2933 return psprintf(
_(
"A result of type %s requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, anycompatiblerange, or anycompatiblemultirange."),
2958 for (
int i = 0;
i < nargs;
i++)
2963 return pstrdup(
_(
"A result of type internal requires at least one input of type internal."));
3059 if (srctype == targettype)
3072 if (srctype == targettype)
3199 elog(
ERROR,
"unrecognized castcontext: %d",
3221 elog(
ERROR,
"unrecognized castmethod: %d",
3396 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 errcode(int sqlerrcode)
int errdetail(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#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 * GetNSItemByVar(ParseState *pstate, Var *var)
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
END_CATALOG_STRUCT typedef 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)
END_CATALOG_STRUCT typedef FormData_pg_proc * Form_pg_proc
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Datum Int32GetDatum(int32 X)
#define PointerGetDatum(X)
char * psprintf(const char *fmt,...)
CoerceParamHook p_coerce_param_hook
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)