PostgreSQL Source Code  git master
parse_coerce.h File Reference
Include dependency graph for parse_coerce.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef char TYPCATEGORY
 
typedef enum CoercionPathType CoercionPathType
 

Enumerations

enum  CoercionPathType {
  COERCION_PATH_NONE, COERCION_PATH_FUNC, COERCION_PATH_RELABELTYPE, COERCION_PATH_ARRAYCOERCE,
  COERCION_PATH_COERCEVIAIO
}
 

Functions

bool IsBinaryCoercible (Oid srctype, Oid targettype)
 
bool IsPreferredType (TYPCATEGORY category, Oid type)
 
TYPCATEGORY TypeCategory (Oid type)
 
Nodecoerce_to_target_type (ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
 
bool can_coerce_type (int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
 
Nodecoerce_type (ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
 
Nodecoerce_to_domain (Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
 
Nodecoerce_to_boolean (ParseState *pstate, Node *node, const char *constructName)
 
Nodecoerce_to_specific_type (ParseState *pstate, Node *node, Oid targetTypeId, const char *constructName)
 
Nodecoerce_to_specific_type_typmod (ParseState *pstate, Node *node, Oid targetTypeId, int32 targetTypmod, const char *constructName)
 
int parser_coercion_errposition (ParseState *pstate, int coerce_location, Node *input_expr)
 
Oid select_common_type (ParseState *pstate, List *exprs, const char *context, Node **which_expr)
 
Nodecoerce_to_common_type (ParseState *pstate, Node *node, Oid targetTypeId, const char *context)
 
bool check_generic_type_consistency (const Oid *actual_arg_types, const Oid *declared_arg_types, int nargs)
 
Oid enforce_generic_type_consistency (const Oid *actual_arg_types, Oid *declared_arg_types, int nargs, Oid rettype, bool allow_poly)
 
char * check_valid_polymorphic_signature (Oid ret_type, const Oid *declared_arg_types, int nargs)
 
char * check_valid_internal_signature (Oid ret_type, const Oid *declared_arg_types, int nargs)
 
CoercionPathType find_coercion_pathway (Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
 
CoercionPathType find_typmod_coercion_function (Oid typeId, Oid *funcid)
 

Typedef Documentation

◆ CoercionPathType

◆ TYPCATEGORY

typedef char TYPCATEGORY

Definition at line 21 of file parse_coerce.h.

Enumeration Type Documentation

◆ CoercionPathType

Enumerator
COERCION_PATH_NONE 
COERCION_PATH_FUNC 
COERCION_PATH_RELABELTYPE 
COERCION_PATH_ARRAYCOERCE 
COERCION_PATH_COERCEVIAIO 

Definition at line 24 of file parse_coerce.h.

25 {
26  COERCION_PATH_NONE, /* failed to find any coercion pathway */
27  COERCION_PATH_FUNC, /* apply the specified coercion function */
28  COERCION_PATH_RELABELTYPE, /* binary-compatible cast, no function */
29  COERCION_PATH_ARRAYCOERCE, /* need an ArrayCoerceExpr node */
30  COERCION_PATH_COERCEVIAIO /* need a CoerceViaIO node */
CoercionPathType
Definition: parse_coerce.h:24

Function Documentation

◆ can_coerce_type()

bool can_coerce_type ( int  nargs,
const Oid input_typeids,
const Oid target_typeids,
CoercionContext  ccontext 
)

Definition at line 546 of file parse_coerce.c.

References check_generic_type_consistency(), COERCION_PATH_NONE, find_coercion_pathway(), i, is_complex_array(), ISCOMPLEX, typeInheritsFrom(), and typeIsOfTypedTable().

Referenced by ATAddForeignKeyConstraint(), coerce_to_common_type(), coerce_to_target_type(), func_match_argtypes(), func_select_candidate(), select_common_type(), select_common_type_from_oids(), and transformFrameOffset().

548 {
549  bool have_generics = false;
550  int i;
551 
552  /* run through argument list... */
553  for (i = 0; i < nargs; i++)
554  {
555  Oid inputTypeId = input_typeids[i];
556  Oid targetTypeId = target_typeids[i];
557  CoercionPathType pathtype;
558  Oid funcId;
559 
560  /* no problem if same type */
561  if (inputTypeId == targetTypeId)
562  continue;
563 
564  /* accept if target is ANY */
565  if (targetTypeId == ANYOID)
566  continue;
567 
568  /* accept if target is polymorphic, for now */
569  if (IsPolymorphicType(targetTypeId))
570  {
571  have_generics = true; /* do more checking later */
572  continue;
573  }
574 
575  /*
576  * If input is an untyped string constant, assume we can convert it to
577  * anything.
578  */
579  if (inputTypeId == UNKNOWNOID)
580  continue;
581 
582  /*
583  * If pg_cast shows that we can coerce, accept. This test now covers
584  * both binary-compatible and coercion-function cases.
585  */
586  pathtype = find_coercion_pathway(targetTypeId, inputTypeId, ccontext,
587  &funcId);
588  if (pathtype != COERCION_PATH_NONE)
589  continue;
590 
591  /*
592  * If input is RECORD and target is a composite type, assume we can
593  * coerce (may need tighter checking here)
594  */
595  if (inputTypeId == RECORDOID &&
596  ISCOMPLEX(targetTypeId))
597  continue;
598 
599  /*
600  * If input is a composite type and target is RECORD, accept
601  */
602  if (targetTypeId == RECORDOID &&
603  ISCOMPLEX(inputTypeId))
604  continue;
605 
606 #ifdef NOT_USED /* not implemented yet */
607 
608  /*
609  * If input is record[] and target is a composite array type, assume
610  * we can coerce (may need tighter checking here)
611  */
612  if (inputTypeId == RECORDARRAYOID &&
613  is_complex_array(targetTypeId))
614  continue;
615 #endif
616 
617  /*
618  * If input is a composite array type and target is record[], accept
619  */
620  if (targetTypeId == RECORDARRAYOID &&
621  is_complex_array(inputTypeId))
622  continue;
623 
624  /*
625  * If input is a class type that inherits from target, accept
626  */
627  if (typeInheritsFrom(inputTypeId, targetTypeId)
628  || typeIsOfTypedTable(inputTypeId, targetTypeId))
629  continue;
630 
631  /*
632  * Else, cannot coerce at this argument position
633  */
634  return false;
635  }
636 
637  /* If we found any generic argument types, cross-check them */
638  if (have_generics)
639  {
640  if (!check_generic_type_consistency(input_typeids, target_typeids,
641  nargs))
642  return false;
643  }
644 
645  return true;
646 }
bool check_generic_type_consistency(const Oid *actual_arg_types, const Oid *declared_arg_types, int nargs)
unsigned int Oid
Definition: postgres_ext.h:31
CoercionPathType
Definition: parse_coerce.h:24
bool typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
Definition: pg_inherits.c:315
#define ISCOMPLEX(typeid)
Definition: parse_type.h:58
static bool typeIsOfTypedTable(Oid reltypeId, Oid reloftypeId)
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
int i
static bool is_complex_array(Oid typid)

◆ check_generic_type_consistency()

bool check_generic_type_consistency ( const Oid actual_arg_types,
const Oid declared_arg_types,
int  nargs 
)

Definition at line 1579 of file parse_coerce.c.

References Assert, FUNC_MAX_ARGS, get_element_type(), get_range_subtype(), getBaseType(), InvalidOid, OidIsValid, select_common_type_from_oids(), type_is_array_domain, and type_is_enum().

Referenced by can_coerce_type().

1582 {
1583  Oid elem_typeid = InvalidOid;
1584  Oid array_typeid = InvalidOid;
1585  Oid range_typeid = InvalidOid;
1586  Oid anycompatible_range_typeid = InvalidOid;
1587  Oid anycompatible_range_typelem = InvalidOid;
1588  bool have_anynonarray = false;
1589  bool have_anyenum = false;
1590  bool have_anycompatible_nonarray = false;
1591  int n_anycompatible_args = 0;
1592  Oid anycompatible_actual_types[FUNC_MAX_ARGS];
1593 
1594  /*
1595  * Loop through the arguments to see if we have any that are polymorphic.
1596  * If so, require the actual types to be consistent.
1597  */
1598  Assert(nargs <= FUNC_MAX_ARGS);
1599  for (int j = 0; j < nargs; j++)
1600  {
1601  Oid decl_type = declared_arg_types[j];
1602  Oid actual_type = actual_arg_types[j];
1603 
1604  if (decl_type == ANYELEMENTOID ||
1605  decl_type == ANYNONARRAYOID ||
1606  decl_type == ANYENUMOID)
1607  {
1608  if (decl_type == ANYNONARRAYOID)
1609  have_anynonarray = true;
1610  else if (decl_type == ANYENUMOID)
1611  have_anyenum = true;
1612  if (actual_type == UNKNOWNOID)
1613  continue;
1614  if (OidIsValid(elem_typeid) && actual_type != elem_typeid)
1615  return false;
1616  elem_typeid = actual_type;
1617  }
1618  else if (decl_type == ANYARRAYOID)
1619  {
1620  if (actual_type == UNKNOWNOID)
1621  continue;
1622  actual_type = getBaseType(actual_type); /* flatten domains */
1623  if (OidIsValid(array_typeid) && actual_type != array_typeid)
1624  return false;
1625  array_typeid = actual_type;
1626  }
1627  else if (decl_type == ANYRANGEOID)
1628  {
1629  if (actual_type == UNKNOWNOID)
1630  continue;
1631  actual_type = getBaseType(actual_type); /* flatten domains */
1632  if (OidIsValid(range_typeid) && actual_type != range_typeid)
1633  return false;
1634  range_typeid = actual_type;
1635  }
1636  else if (decl_type == ANYCOMPATIBLEOID ||
1637  decl_type == ANYCOMPATIBLENONARRAYOID)
1638  {
1639  if (decl_type == ANYCOMPATIBLENONARRAYOID)
1640  have_anycompatible_nonarray = true;
1641  if (actual_type == UNKNOWNOID)
1642  continue;
1643  /* collect the actual types of non-unknown COMPATIBLE args */
1644  anycompatible_actual_types[n_anycompatible_args++] = actual_type;
1645  }
1646  else if (decl_type == ANYCOMPATIBLEARRAYOID)
1647  {
1648  Oid elem_type;
1649 
1650  if (actual_type == UNKNOWNOID)
1651  continue;
1652  actual_type = getBaseType(actual_type); /* flatten domains */
1653  elem_type = get_element_type(actual_type);
1654  if (!OidIsValid(elem_type))
1655  return false; /* not an array */
1656  /* collect the element type for common-supertype choice */
1657  anycompatible_actual_types[n_anycompatible_args++] = elem_type;
1658  }
1659  else if (decl_type == ANYCOMPATIBLERANGEOID)
1660  {
1661  if (actual_type == UNKNOWNOID)
1662  continue;
1663  actual_type = getBaseType(actual_type); /* flatten domains */
1664  if (OidIsValid(anycompatible_range_typeid))
1665  {
1666  /* All ANYCOMPATIBLERANGE arguments must be the same type */
1667  if (anycompatible_range_typeid != actual_type)
1668  return false;
1669  }
1670  else
1671  {
1672  anycompatible_range_typeid = actual_type;
1673  anycompatible_range_typelem = get_range_subtype(actual_type);
1674  if (!OidIsValid(anycompatible_range_typelem))
1675  return false; /* not a range type */
1676  /* collect the subtype for common-supertype choice */
1677  anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
1678  }
1679  }
1680  }
1681 
1682  /* Get the element type based on the array type, if we have one */
1683  if (OidIsValid(array_typeid))
1684  {
1685  if (array_typeid == ANYARRAYOID)
1686  {
1687  /*
1688  * Special case for matching ANYARRAY input to an ANYARRAY
1689  * argument: allow it for now. enforce_generic_type_consistency()
1690  * might complain later, depending on the presence of other
1691  * polymorphic arguments or results, but it will deliver a less
1692  * surprising error message than "function does not exist".
1693  *
1694  * (If you think to change this, note that can_coerce_type will
1695  * consider such a situation as a match, so that we might not even
1696  * get here.)
1697  */
1698  }
1699  else
1700  {
1701  Oid array_typelem;
1702 
1703  array_typelem = get_element_type(array_typeid);
1704  if (!OidIsValid(array_typelem))
1705  return false; /* should be an array, but isn't */
1706 
1707  if (!OidIsValid(elem_typeid))
1708  {
1709  /*
1710  * if we don't have an element type yet, use the one we just
1711  * got
1712  */
1713  elem_typeid = array_typelem;
1714  }
1715  else if (array_typelem != elem_typeid)
1716  {
1717  /* otherwise, they better match */
1718  return false;
1719  }
1720  }
1721  }
1722 
1723  /* Get the element type based on the range type, if we have one */
1724  if (OidIsValid(range_typeid))
1725  {
1726  Oid range_typelem;
1727 
1728  range_typelem = get_range_subtype(range_typeid);
1729  if (!OidIsValid(range_typelem))
1730  return false; /* should be a range, but isn't */
1731 
1732  if (!OidIsValid(elem_typeid))
1733  {
1734  /*
1735  * if we don't have an element type yet, use the one we just got
1736  */
1737  elem_typeid = range_typelem;
1738  }
1739  else if (range_typelem != elem_typeid)
1740  {
1741  /* otherwise, they better match */
1742  return false;
1743  }
1744  }
1745 
1746  if (have_anynonarray)
1747  {
1748  /* require the element type to not be an array or domain over array */
1749  if (type_is_array_domain(elem_typeid))
1750  return false;
1751  }
1752 
1753  if (have_anyenum)
1754  {
1755  /* require the element type to be an enum */
1756  if (!type_is_enum(elem_typeid))
1757  return false;
1758  }
1759 
1760  /* Check matching of ANYCOMPATIBLE-family arguments, if any */
1761  if (n_anycompatible_args > 0)
1762  {
1763  Oid anycompatible_typeid;
1764 
1765  anycompatible_typeid =
1766  select_common_type_from_oids(n_anycompatible_args,
1767  anycompatible_actual_types,
1768  true);
1769 
1770  if (!OidIsValid(anycompatible_typeid))
1771  return false; /* there's no common supertype */
1772 
1773  if (have_anycompatible_nonarray)
1774  {
1775  /*
1776  * require the anycompatible type to not be an array or domain
1777  * over array
1778  */
1779  if (type_is_array_domain(anycompatible_typeid))
1780  return false;
1781  }
1782 
1783  /*
1784  * the anycompatible type must exactly match the range element type,
1785  * if we were able to identify one
1786  */
1787  if (OidIsValid(anycompatible_range_typelem) &&
1788  anycompatible_range_typelem != anycompatible_typeid)
1789  return false;
1790  }
1791 
1792  /* Looks valid */
1793  return true;
1794 }
#define type_is_array_domain(typid)
Definition: lsyscache.h:193
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2636
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:652
static Oid select_common_type_from_oids(int nargs, const Oid *typeids, bool noerror)
#define FUNC_MAX_ARGS
#define InvalidOid
Definition: postgres_ext.h:36
#define Assert(condition)
Definition: c.h:746
bool type_is_enum(Oid typid)
Definition: lsyscache.c:2566
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409
Oid get_range_subtype(Oid rangeOid)
Definition: lsyscache.c:3232

◆ check_valid_internal_signature()

char* check_valid_internal_signature ( Oid  ret_type,
const Oid declared_arg_types,
int  nargs 
)

Definition at line 2476 of file parse_coerce.c.

References _, i, and pstrdup().

Referenced by AggregateCreate(), and ProcedureCreate().

2479 {
2480  if (ret_type == INTERNALOID)
2481  {
2482  for (int i = 0; i < nargs; i++)
2483  {
2484  if (declared_arg_types[i] == ret_type)
2485  return NULL; /* OK */
2486  }
2487  return pstrdup(_("A result of type internal requires at least one input of type internal."));
2488  }
2489  else
2490  return NULL; /* OK, ret_type is not INTERNAL */
2491 }
char * pstrdup(const char *in)
Definition: mcxt.c:1187
int i
#define _(x)
Definition: elog.c:88

◆ check_valid_polymorphic_signature()

char* check_valid_polymorphic_signature ( Oid  ret_type,
const Oid declared_arg_types,
int  nargs 
)

Definition at line 2417 of file parse_coerce.c.

References _, format_type_be(), i, and psprintf().

Referenced by AggregateCreate(), and ProcedureCreate().

2420 {
2421  if (ret_type == ANYRANGEOID || ret_type == ANYCOMPATIBLERANGEOID)
2422  {
2423  /*
2424  * ANYRANGE requires an ANYRANGE input, else we can't tell which of
2425  * several range types with the same element type to use. Likewise
2426  * for ANYCOMPATIBLERANGE.
2427  */
2428  for (int i = 0; i < nargs; i++)
2429  {
2430  if (declared_arg_types[i] == ret_type)
2431  return NULL; /* OK */
2432  }
2433  return psprintf(_("A result of type %s requires at least one input of type %s."),
2434  format_type_be(ret_type), format_type_be(ret_type));
2435  }
2436  else if (IsPolymorphicTypeFamily1(ret_type))
2437  {
2438  /* Otherwise, any family-1 type can be deduced from any other */
2439  for (int i = 0; i < nargs; i++)
2440  {
2441  if (IsPolymorphicTypeFamily1(declared_arg_types[i]))
2442  return NULL; /* OK */
2443  }
2444  /* Keep this list in sync with IsPolymorphicTypeFamily1! */
2445  return psprintf(_("A result of type %s requires at least one input of type anyelement, anyarray, anynonarray, anyenum, or anyrange."),
2446  format_type_be(ret_type));
2447  }
2448  else if (IsPolymorphicTypeFamily2(ret_type))
2449  {
2450  /* Otherwise, any family-2 type can be deduced from any other */
2451  for (int i = 0; i < nargs; i++)
2452  {
2453  if (IsPolymorphicTypeFamily2(declared_arg_types[i]))
2454  return NULL; /* OK */
2455  }
2456  /* Keep this list in sync with IsPolymorphicTypeFamily2! */
2457  return psprintf(_("A result of type %s requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, or anycompatiblerange."),
2458  format_type_be(ret_type));
2459  }
2460  else
2461  return NULL; /* OK, ret_type is not polymorphic */
2462 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
int i
#define _(x)
Definition: elog.c:88

◆ coerce_to_boolean()

Node* coerce_to_boolean ( ParseState pstate,
Node node,
const char *  constructName 
)

Definition at line 1135 of file parse_coerce.c.

References COERCE_IMPLICIT_CAST, coerce_to_target_type(), COERCION_ASSIGNMENT, ereport, errcode(), errmsg(), ERROR, expression_returns_set(), exprLocation(), exprType(), format_type_be(), and parser_errposition().

Referenced by cookConstraint(), DoCopy(), domainAddConstraint(), transformAExprIn(), transformBooleanTest(), transformBoolExpr(), transformCaseExpr(), transformJoinUsingClause(), transformWhereClause(), and transformXmlExpr().

1137 {
1138  Oid inputTypeId = exprType(node);
1139 
1140  if (inputTypeId != BOOLOID)
1141  {
1142  Node *newnode;
1143 
1144  newnode = coerce_to_target_type(pstate, node, inputTypeId,
1145  BOOLOID, -1,
1148  -1);
1149  if (newnode == NULL)
1150  ereport(ERROR,
1151  (errcode(ERRCODE_DATATYPE_MISMATCH),
1152  /* translator: first %s is name of a SQL construct, eg WHERE */
1153  errmsg("argument of %s must be type %s, not type %s",
1154  constructName, "boolean",
1155  format_type_be(inputTypeId)),
1156  parser_errposition(pstate, exprLocation(node))));
1157  node = newnode;
1158  }
1159 
1160  if (expression_returns_set(node))
1161  ereport(ERROR,
1162  (errcode(ERRCODE_DATATYPE_MISMATCH),
1163  /* translator: %s is name of a SQL construct, eg WHERE */
1164  errmsg("argument of %s must not return a set",
1165  constructName),
1166  parser_errposition(pstate, exprLocation(node))));
1167 
1168  return node;
1169 }
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1240
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:718
Definition: nodes.h:528
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:77
#define ereport(elevel,...)
Definition: elog.h:144
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:821

◆ coerce_to_common_type()

Node* coerce_to_common_type ( ParseState pstate,
Node node,
Oid  targetTypeId,
const char *  context 
)

Definition at line 1503 of file parse_coerce.c.

References can_coerce_type(), COERCE_IMPLICIT_CAST, coerce_type(), COERCION_IMPLICIT, ereport, errcode(), errmsg(), ERROR, exprLocation(), exprType(), format_type_be(), and parser_errposition().

Referenced by generate_setop_tlist(), transformAExprIn(), transformArrayExpr(), transformCaseExpr(), transformCoalesceExpr(), transformMinMaxExpr(), transformSetOperationTree(), and transformValuesClause().

1505 {
1506  Oid inputTypeId = exprType(node);
1507 
1508  if (inputTypeId == targetTypeId)
1509  return node; /* no work */
1510  if (can_coerce_type(1, &inputTypeId, &targetTypeId, COERCION_IMPLICIT))
1511  node = coerce_type(pstate, node, inputTypeId, targetTypeId, -1,
1513  else
1514  ereport(ERROR,
1515  (errcode(ERRCODE_CANNOT_COERCE),
1516  /* translator: first %s is name of a SQL construct, eg CASE */
1517  errmsg("%s could not convert type %s to %s",
1518  context,
1519  format_type_be(inputTypeId),
1520  format_type_be(targetTypeId)),
1521  parser_errposition(pstate, exprLocation(node))));
1522  return node;
1523 }
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1240
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
Definition: parse_coerce.c:546
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:155
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:821

◆ coerce_to_domain()

Node* coerce_to_domain ( Node arg,
Oid  baseTypeId,
int32  baseTypeMod,
Oid  typeId,
CoercionContext  ccontext,
CoercionForm  cformat,
int  location,
bool  hideInputCoercion 
)

Definition at line 666 of file parse_coerce.c.

References arg, CoerceToDomain::arg, COERCE_IMPLICIT_CAST, coerce_type_typmod(), CoerceToDomain::coercionformat, getBaseTypeAndTypmod(), hide_coercion_node(), InvalidOid, CoerceToDomain::location, makeNode, CoerceToDomain::resulttype, and CoerceToDomain::resulttypmod.

Referenced by coerce_record_to_complex(), coerce_type(), expand_targetlist(), ReplaceVarsFromTargetList_callback(), rewriteTargetListIU(), rewriteValuesRTE(), and transformAssignmentIndirection().

669 {
670  CoerceToDomain *result;
671 
672  /* Get the base type if it hasn't been supplied */
673  if (baseTypeId == InvalidOid)
674  baseTypeId = getBaseTypeAndTypmod(typeId, &baseTypeMod);
675 
676  /* If it isn't a domain, return the node as it was passed in */
677  if (baseTypeId == typeId)
678  return arg;
679 
680  /* Suppress display of nested coercion steps */
681  if (hideInputCoercion)
682  hide_coercion_node(arg);
683 
684  /*
685  * If the domain applies a typmod to its base type, build the appropriate
686  * coercion step. Mark it implicit for display purposes, because we don't
687  * want it shown separately by ruleutils.c; but the isExplicit flag passed
688  * to the conversion function depends on the manner in which the domain
689  * coercion is invoked, so that the semantics of implicit and explicit
690  * coercion differ. (Is that really the behavior we want?)
691  *
692  * NOTE: because we apply this as part of the fixed expression structure,
693  * ALTER DOMAIN cannot alter the typtypmod. But it's unclear that that
694  * would be safe to do anyway, without lots of knowledge about what the
695  * base type thinks the typmod means.
696  */
697  arg = coerce_type_typmod(arg, baseTypeId, baseTypeMod,
698  ccontext, COERCE_IMPLICIT_CAST, location,
699  false);
700 
701  /*
702  * Now build the domain coercion node. This represents run-time checking
703  * of any constraints currently attached to the domain. This also ensures
704  * that the expression is properly labeled as to result type.
705  */
706  result = makeNode(CoerceToDomain);
707  result->arg = (Expr *) arg;
708  result->resulttype = typeId;
709  result->resulttypmod = -1; /* currently, always -1 for domains */
710  /* resultcollid will be set by parse_collate.c */
711  result->coercionformat = cformat;
712  result->location = location;
713 
714  return (Node *) result;
715 }
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2426
int32 resulttypmod
Definition: primnodes.h:1264
Definition: nodes.h:528
CoercionForm coercionformat
Definition: primnodes.h:1266
static void hide_coercion_node(Node *node)
Definition: parse_coerce.c:785
static Node * coerce_type_typmod(Node *node, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Definition: parse_coerce.c:743
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:576
void * arg

◆ coerce_to_specific_type()

Node* coerce_to_specific_type ( ParseState pstate,
Node node,
Oid  targetTypeId,
const char *  constructName 
)

Definition at line 1231 of file parse_coerce.c.

References coerce_to_specific_type_typmod().

Referenced by interpret_function_parameter_list(), transformFrameOffset(), transformLimitClause(), transformRangeTableFunc(), transformRangeTableSample(), transformXmlExpr(), and transformXmlSerialize().

1234 {
1235  return coerce_to_specific_type_typmod(pstate, node,
1236  targetTypeId, -1,
1237  constructName);
1238 }
Node * coerce_to_specific_type_typmod(ParseState *pstate, Node *node, Oid targetTypeId, int32 targetTypmod, const char *constructName)

◆ coerce_to_specific_type_typmod()

Node* coerce_to_specific_type_typmod ( ParseState pstate,
Node node,
Oid  targetTypeId,
int32  targetTypmod,
const char *  constructName 
)

Definition at line 1182 of file parse_coerce.c.

References COERCE_IMPLICIT_CAST, coerce_to_target_type(), COERCION_ASSIGNMENT, ereport, errcode(), errmsg(), ERROR, expression_returns_set(), exprLocation(), exprType(), format_type_be(), and parser_errposition().

Referenced by coerce_to_specific_type(), and transformRangeTableFunc().

1185 {
1186  Oid inputTypeId = exprType(node);
1187 
1188  if (inputTypeId != targetTypeId)
1189  {
1190  Node *newnode;
1191 
1192  newnode = coerce_to_target_type(pstate, node, inputTypeId,
1193  targetTypeId, targetTypmod,
1196  -1);
1197  if (newnode == NULL)
1198  ereport(ERROR,
1199  (errcode(ERRCODE_DATATYPE_MISMATCH),
1200  /* translator: first %s is name of a SQL construct, eg LIMIT */
1201  errmsg("argument of %s must be type %s, not type %s",
1202  constructName,
1203  format_type_be(targetTypeId),
1204  format_type_be(inputTypeId)),
1205  parser_errposition(pstate, exprLocation(node))));
1206  node = newnode;
1207  }
1208 
1209  if (expression_returns_set(node))
1210  ereport(ERROR,
1211  (errcode(ERRCODE_DATATYPE_MISMATCH),
1212  /* translator: %s is name of a SQL construct, eg LIMIT */
1213  errmsg("argument of %s must not return a set",
1214  constructName),
1215  parser_errposition(pstate, exprLocation(node))));
1216 
1217  return node;
1218 }
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1240
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:718
Definition: nodes.h:528
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
#define ERROR
Definition: elog.h:43
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:77
#define ereport(elevel,...)
Definition: elog.h:144
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:821

◆ coerce_to_target_type()

Node* coerce_to_target_type ( ParseState pstate,
Node expr,
Oid  exprtype,
Oid  targettype,
int32  targettypmod,
CoercionContext  ccontext,
CoercionForm  cformat,
int  location 
)

Definition at line 77 of file parse_coerce.c.

References arg, CollateExpr::arg, can_coerce_type(), coerce_type(), coerce_type_typmod(), CollateExpr::collOid, IsA, CollateExpr::location, and makeNode.

Referenced by ATExecAddColumn(), ATExecAlterColumnType(), ATPrepAlterColumnType(), build_coercion_expression(), build_column_default(), coerce_fn_result_column(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_specific_type_typmod(), cookDefault(), EvaluateParams(), get_cast_hashentry(), transformArrayExpr(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformContainerSubscripts(), transformPartitionBoundValue(), transformTypeCast(), and transformXmlSerialize().

82 {
83  Node *result;
84  Node *origexpr;
85 
86  if (!can_coerce_type(1, &exprtype, &targettype, ccontext))
87  return NULL;
88 
89  /*
90  * If the input has a CollateExpr at the top, strip it off, perform the
91  * coercion, and put a new one back on. This is annoying since it
92  * duplicates logic in coerce_type, but if we don't do this then it's too
93  * hard to tell whether coerce_type actually changed anything, and we
94  * *must* know that to avoid possibly calling hide_coercion_node on
95  * something that wasn't generated by coerce_type. Note that if there are
96  * multiple stacked CollateExprs, we just discard all but the topmost.
97  */
98  origexpr = expr;
99  while (expr && IsA(expr, CollateExpr))
100  expr = (Node *) ((CollateExpr *) expr)->arg;
101 
102  result = coerce_type(pstate, expr, exprtype,
103  targettype, targettypmod,
104  ccontext, cformat, location);
105 
106  /*
107  * If the target is a fixed-length type, it may need a length coercion as
108  * well as a type coercion. If we find ourselves adding both, force the
109  * inner coercion node to implicit display form.
110  */
111  result = coerce_type_typmod(result,
112  targettype, targettypmod,
113  ccontext, cformat, location,
114  (result != expr && !IsA(result, Const)));
115 
116  if (expr != origexpr)
117  {
118  /* Reinstall top CollateExpr */
119  CollateExpr *coll = (CollateExpr *) origexpr;
120  CollateExpr *newcoll = makeNode(CollateExpr);
121 
122  newcoll->arg = (Expr *) result;
123  newcoll->collOid = coll->collOid;
124  newcoll->location = coll->location;
125  result = (Node *) newcoll;
126  }
127 
128  return result;
129 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
Definition: parse_coerce.c:546
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:155
Definition: nodes.h:528
static Node * coerce_type_typmod(Node *node, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Definition: parse_coerce.c:743
#define makeNode(_type_)
Definition: nodes.h:576
Expr * arg
Definition: primnodes.h:903
void * arg
int location
Definition: primnodes.h:905

◆ coerce_type()

Node* coerce_type ( ParseState pstate,
Node node,
Oid  inputTypeId,
Oid  targetTypeId,
int32  targetTypeMod,
CoercionContext  ccontext,
CoercionForm  cformat,
int  location 
)

Definition at line 155 of file parse_coerce.c.

References ConvertRowtypeExpr::arg, CollateExpr::arg, build_coercion_expression(), cancel_parser_errposition_callback(), COERCE_IMPLICIT_CAST, coerce_record_to_complex(), coerce_to_domain(), coerce_type(), COERCION_PATH_NONE, COERCION_PATH_RELABELTYPE, CollateExpr::collOid, Const::constbyval, Const::constcollid, Const::constisnull, Const::constlen, Const::consttype, Const::consttypmod, Const::constvalue, ConvertRowtypeExpr::convertformat, DatumGetCString, datumIsEqual(), elog, ERROR, find_coercion_pathway(), format_type_be(), getBaseType(), getBaseTypeAndTypmod(), InvalidOid, is_complex_array(), IsA, ISCOMPLEX, Const::location, RelabelType::location, ConvertRowtypeExpr::location, CollateExpr::location, makeNode, makeRelabelType(), ParseState::p_coerce_param_hook, PG_DETOAST_DATUM, PointerGetDatum, ReleaseSysCache(), ConvertRowtypeExpr::resulttype, setup_parser_errposition_callback(), stringTypeDatum(), typeByVal(), typeidType(), typeInheritsFrom(), typeIsOfTypedTable(), typeLen(), typeTypeCollation(), typeTypeName(), and WARNING.

Referenced by addTargetToGroupList(), addTargetToSortList(), buildMergedJoinVar(), coerce_to_common_type(), coerce_to_target_type(), coerce_type(), make_fn_arguments(), ParseFuncOrColumn(), resolveTargetListUnknowns(), transformArrayExpr(), and unify_hypothetical_args().

158 {
159  Node *result;
160  CoercionPathType pathtype;
161  Oid funcId;
162 
163  if (targetTypeId == inputTypeId ||
164  node == NULL)
165  {
166  /* no conversion needed */
167  return node;
168  }
169  if (targetTypeId == ANYOID ||
170  targetTypeId == ANYELEMENTOID ||
171  targetTypeId == ANYNONARRAYOID ||
172  targetTypeId == ANYCOMPATIBLEOID ||
173  targetTypeId == ANYCOMPATIBLENONARRAYOID)
174  {
175  /*
176  * Assume can_coerce_type verified that implicit coercion is okay.
177  *
178  * Note: by returning the unmodified node here, we are saying that
179  * it's OK to treat an UNKNOWN constant as a valid input for a
180  * function accepting one of these pseudotypes. This should be all
181  * right, since an UNKNOWN value is still a perfectly valid Datum.
182  *
183  * NB: we do NOT want a RelabelType here: the exposed type of the
184  * function argument must be its actual type, not the polymorphic
185  * pseudotype.
186  */
187  return node;
188  }
189  if (targetTypeId == ANYARRAYOID ||
190  targetTypeId == ANYENUMOID ||
191  targetTypeId == ANYRANGEOID ||
192  targetTypeId == ANYCOMPATIBLEARRAYOID ||
193  targetTypeId == ANYCOMPATIBLERANGEOID)
194  {
195  /*
196  * Assume can_coerce_type verified that implicit coercion is okay.
197  *
198  * These cases are unlike the ones above because the exposed type of
199  * the argument must be an actual array, enum, or range type. In
200  * particular the argument must *not* be an UNKNOWN constant. If it
201  * is, we just fall through; below, we'll call the pseudotype's input
202  * function, which will produce an error. Also, if what we have is a
203  * domain over array, enum, or range, we have to relabel it to its
204  * base type.
205  *
206  * Note: currently, we can't actually see a domain-over-enum here,
207  * since the other functions in this file will not match such a
208  * parameter to ANYENUM. But that should get changed eventually.
209  */
210  if (inputTypeId != UNKNOWNOID)
211  {
212  Oid baseTypeId = getBaseType(inputTypeId);
213 
214  if (baseTypeId != inputTypeId)
215  {
216  RelabelType *r = makeRelabelType((Expr *) node,
217  baseTypeId, -1,
218  InvalidOid,
219  cformat);
220 
221  r->location = location;
222  return (Node *) r;
223  }
224  /* Not a domain type, so return it as-is */
225  return node;
226  }
227  }
228  if (inputTypeId == UNKNOWNOID && IsA(node, Const))
229  {
230  /*
231  * Input is a string constant with previously undetermined type. Apply
232  * the target type's typinput function to it to produce a constant of
233  * the target type.
234  *
235  * NOTE: this case cannot be folded together with the other
236  * constant-input case, since the typinput function does not
237  * necessarily behave the same as a type conversion function. For
238  * example, int4's typinput function will reject "1.2", whereas
239  * float-to-int type conversion will round to integer.
240  *
241  * XXX if the typinput function is not immutable, we really ought to
242  * postpone evaluation of the function call until runtime. But there
243  * is no way to represent a typinput function call as an expression
244  * tree, because C-string values are not Datums. (XXX This *is*
245  * possible as of 7.3, do we want to do it?)
246  */
247  Const *con = (Const *) node;
248  Const *newcon = makeNode(Const);
249  Oid baseTypeId;
250  int32 baseTypeMod;
251  int32 inputTypeMod;
252  Type baseType;
253  ParseCallbackState pcbstate;
254 
255  /*
256  * If the target type is a domain, we want to call its base type's
257  * input routine, not domain_in(). This is to avoid premature failure
258  * when the domain applies a typmod: existing input routines follow
259  * implicit-coercion semantics for length checks, which is not always
260  * what we want here. The needed check will be applied properly
261  * inside coerce_to_domain().
262  */
263  baseTypeMod = targetTypeMod;
264  baseTypeId = getBaseTypeAndTypmod(targetTypeId, &baseTypeMod);
265 
266  /*
267  * For most types we pass typmod -1 to the input routine, because
268  * existing input routines follow implicit-coercion semantics for
269  * length checks, which is not always what we want here. Any length
270  * constraint will be applied later by our caller. An exception
271  * however is the INTERVAL type, for which we *must* pass the typmod
272  * or it won't be able to obey the bizarre SQL-spec input rules. (Ugly
273  * as sin, but so is this part of the spec...)
274  */
275  if (baseTypeId == INTERVALOID)
276  inputTypeMod = baseTypeMod;
277  else
278  inputTypeMod = -1;
279 
280  baseType = typeidType(baseTypeId);
281 
282  newcon->consttype = baseTypeId;
283  newcon->consttypmod = inputTypeMod;
284  newcon->constcollid = typeTypeCollation(baseType);
285  newcon->constlen = typeLen(baseType);
286  newcon->constbyval = typeByVal(baseType);
287  newcon->constisnull = con->constisnull;
288 
289  /*
290  * We use the original literal's location regardless of the position
291  * of the coercion. This is a change from pre-9.2 behavior, meant to
292  * simplify life for pg_stat_statements.
293  */
294  newcon->location = con->location;
295 
296  /*
297  * Set up to point at the constant's text if the input routine throws
298  * an error.
299  */
300  setup_parser_errposition_callback(&pcbstate, pstate, con->location);
301 
302  /*
303  * We assume here that UNKNOWN's internal representation is the same
304  * as CSTRING.
305  */
306  if (!con->constisnull)
307  newcon->constvalue = stringTypeDatum(baseType,
309  inputTypeMod);
310  else
311  newcon->constvalue = stringTypeDatum(baseType,
312  NULL,
313  inputTypeMod);
314 
315  /*
316  * If it's a varlena value, force it to be in non-expanded
317  * (non-toasted) format; this avoids any possible dependency on
318  * external values and improves consistency of representation.
319  */
320  if (!con->constisnull && newcon->constlen == -1)
321  newcon->constvalue =
323 
324 #ifdef RANDOMIZE_ALLOCATED_MEMORY
325 
326  /*
327  * For pass-by-reference data types, repeat the conversion to see if
328  * the input function leaves any uninitialized bytes in the result. We
329  * can only detect that reliably if RANDOMIZE_ALLOCATED_MEMORY is
330  * enabled, so we don't bother testing otherwise. The reason we don't
331  * want any instability in the input function is that comparison of
332  * Const nodes relies on bytewise comparison of the datums, so if the
333  * input function leaves garbage then subexpressions that should be
334  * identical may not get recognized as such. See pgsql-hackers
335  * discussion of 2008-04-04.
336  */
337  if (!con->constisnull && !newcon->constbyval)
338  {
339  Datum val2;
340 
341  val2 = stringTypeDatum(baseType,
343  inputTypeMod);
344  if (newcon->constlen == -1)
345  val2 = PointerGetDatum(PG_DETOAST_DATUM(val2));
346  if (!datumIsEqual(newcon->constvalue, val2, false, newcon->constlen))
347  elog(WARNING, "type %s has unstable input conversion for \"%s\"",
348  typeTypeName(baseType), DatumGetCString(con->constvalue));
349  }
350 #endif
351 
353 
354  result = (Node *) newcon;
355 
356  /* If target is a domain, apply constraints. */
357  if (baseTypeId != targetTypeId)
358  result = coerce_to_domain(result,
359  baseTypeId, baseTypeMod,
360  targetTypeId,
361  ccontext, cformat, location,
362  false);
363 
364  ReleaseSysCache(baseType);
365 
366  return result;
367  }
368  if (IsA(node, Param) &&
369  pstate != NULL && pstate->p_coerce_param_hook != NULL)
370  {
371  /*
372  * Allow the CoerceParamHook to decide what happens. It can return a
373  * transformed node (very possibly the same Param node), or return
374  * NULL to indicate we should proceed with normal coercion.
375  */
376  result = pstate->p_coerce_param_hook(pstate,
377  (Param *) node,
378  targetTypeId,
379  targetTypeMod,
380  location);
381  if (result)
382  return result;
383  }
384  if (IsA(node, CollateExpr))
385  {
386  /*
387  * If we have a COLLATE clause, we have to push the coercion
388  * underneath the COLLATE. This is really ugly, but there is little
389  * choice because the above hacks on Consts and Params wouldn't happen
390  * otherwise. This kluge has consequences in coerce_to_target_type.
391  */
392  CollateExpr *coll = (CollateExpr *) node;
393  CollateExpr *newcoll = makeNode(CollateExpr);
394 
395  newcoll->arg = (Expr *)
396  coerce_type(pstate, (Node *) coll->arg,
397  inputTypeId, targetTypeId, targetTypeMod,
398  ccontext, cformat, location);
399  newcoll->collOid = coll->collOid;
400  newcoll->location = coll->location;
401  return (Node *) newcoll;
402  }
403  pathtype = find_coercion_pathway(targetTypeId, inputTypeId, ccontext,
404  &funcId);
405  if (pathtype != COERCION_PATH_NONE)
406  {
407  if (pathtype != COERCION_PATH_RELABELTYPE)
408  {
409  /*
410  * Generate an expression tree representing run-time application
411  * of the conversion function. If we are dealing with a domain
412  * target type, the conversion function will yield the base type,
413  * and we need to extract the correct typmod to use from the
414  * domain's typtypmod.
415  */
416  Oid baseTypeId;
417  int32 baseTypeMod;
418 
419  baseTypeMod = targetTypeMod;
420  baseTypeId = getBaseTypeAndTypmod(targetTypeId, &baseTypeMod);
421 
422  result = build_coercion_expression(node, pathtype, funcId,
423  baseTypeId, baseTypeMod,
424  ccontext, cformat, location);
425 
426  /*
427  * If domain, coerce to the domain type and relabel with domain
428  * type ID, hiding the previous coercion node.
429  */
430  if (targetTypeId != baseTypeId)
431  result = coerce_to_domain(result, baseTypeId, baseTypeMod,
432  targetTypeId,
433  ccontext, cformat, location,
434  true);
435  }
436  else
437  {
438  /*
439  * We don't need to do a physical conversion, but we do need to
440  * attach a RelabelType node so that the expression will be seen
441  * to have the intended type when inspected by higher-level code.
442  *
443  * Also, domains may have value restrictions beyond the base type
444  * that must be accounted for. If the destination is a domain
445  * then we won't need a RelabelType node.
446  */
447  result = coerce_to_domain(node, InvalidOid, -1, targetTypeId,
448  ccontext, cformat, location,
449  false);
450  if (result == node)
451  {
452  /*
453  * XXX could we label result with exprTypmod(node) instead of
454  * default -1 typmod, to save a possible length-coercion
455  * later? Would work if both types have same interpretation of
456  * typmod, which is likely but not certain.
457  */
458  RelabelType *r = makeRelabelType((Expr *) result,
459  targetTypeId, -1,
460  InvalidOid,
461  cformat);
462 
463  r->location = location;
464  result = (Node *) r;
465  }
466  }
467  return result;
468  }
469  if (inputTypeId == RECORDOID &&
470  ISCOMPLEX(targetTypeId))
471  {
472  /* Coerce a RECORD to a specific complex type */
473  return coerce_record_to_complex(pstate, node, targetTypeId,
474  ccontext, cformat, location);
475  }
476  if (targetTypeId == RECORDOID &&
477  ISCOMPLEX(inputTypeId))
478  {
479  /* Coerce a specific complex type to RECORD */
480  /* NB: we do NOT want a RelabelType here */
481  return node;
482  }
483 #ifdef NOT_USED
484  if (inputTypeId == RECORDARRAYOID &&
485  is_complex_array(targetTypeId))
486  {
487  /* Coerce record[] to a specific complex array type */
488  /* not implemented yet ... */
489  }
490 #endif
491  if (targetTypeId == RECORDARRAYOID &&
492  is_complex_array(inputTypeId))
493  {
494  /* Coerce a specific complex array type to record[] */
495  /* NB: we do NOT want a RelabelType here */
496  return node;
497  }
498  if (typeInheritsFrom(inputTypeId, targetTypeId)
499  || typeIsOfTypedTable(inputTypeId, targetTypeId))
500  {
501  /*
502  * Input class type is a subclass of target, so generate an
503  * appropriate runtime conversion (removing unneeded columns and
504  * possibly rearranging the ones that are wanted).
505  *
506  * We will also get here when the input is a domain over a subclass of
507  * the target type. To keep life simple for the executor, we define
508  * ConvertRowtypeExpr as only working between regular composite types;
509  * therefore, in such cases insert a RelabelType to smash the input
510  * expression down to its base type.
511  */
512  Oid baseTypeId = getBaseType(inputTypeId);
514 
515  if (baseTypeId != inputTypeId)
516  {
517  RelabelType *rt = makeRelabelType((Expr *) node,
518  baseTypeId, -1,
519  InvalidOid,
521 
522  rt->location = location;
523  node = (Node *) rt;
524  }
525  r->arg = (Expr *) node;
526  r->resulttype = targetTypeId;
527  r->convertformat = cformat;
528  r->location = location;
529  return (Node *) r;
530  }
531  /* If we get here, caller blew it */
532  elog(ERROR, "failed to find conversion function from %s to %s",
533  format_type_be(inputTypeId), format_type_be(targetTypeId));
534  return NULL; /* keep compiler quiet */
535 }
Datum constvalue
Definition: primnodes.h:214
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition: lsyscache.c:2426
Oid typeTypeCollation(Type typ)
Definition: parse_type.c:638
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
bool constbyval
Definition: primnodes.h:217
int16 typeLen(Type t)
Definition: parse_type.c:597
#define PointerGetDatum(X)
Definition: postgres.h:556
bool datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen)
Definition: datum.c:222
CoerceParamHook p_coerce_param_hook
Definition: parse_node.h:221
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:155
Definition: nodes.h:528
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
CoercionPathType
Definition: parse_coerce.h:24
signed int int32
Definition: c.h:363
int constlen
Definition: primnodes.h:213
Oid consttype
Definition: primnodes.h:210
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
Definition: parse_node.c:160
bool typeByVal(Type t)
Definition: parse_type.c:607
#define ERROR
Definition: elog.h:43
#define DatumGetCString(X)
Definition: postgres.h:566
char * typeTypeName(Type t)
Definition: parse_type.c:617
Datum stringTypeDatum(Type tp, char *string, int32 atttypmod)
Definition: parse_type.c:652
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Definition: parse_coerce.c:666
Oid constcollid
Definition: primnodes.h:212
RelabelType * makeRelabelType(Expr *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat)
Definition: makefuncs.c:402
static Node * build_coercion_expression(Node *node, CoercionPathType pathtype, Oid funcId, Oid targetTypeId, int32 targetTypMod, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:813
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
Definition: parse_node.c:144
#define WARNING
Definition: elog.h:40
int location
Definition: primnodes.h:221
uintptr_t Datum
Definition: postgres.h:367
CoercionForm convertformat
Definition: primnodes.h:889
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define makeNode(_type_)
Definition: nodes.h:576
bool typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
Definition: pg_inherits.c:315
#define ISCOMPLEX(typeid)
Definition: parse_type.h:58
static bool typeIsOfTypedTable(Oid reltypeId, Oid reloftypeId)
Expr * arg
Definition: primnodes.h:903
static Node * coerce_record_to_complex(ParseState *pstate, Node *node, Oid targetTypeId, CoercionContext ccontext, CoercionForm cformat, int location)
Definition: parse_coerce.c:986
int32 consttypmod
Definition: primnodes.h:211
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
#define elog(elevel,...)
Definition: elog.h:214
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240
static bool is_complex_array(Oid typid)
Type typeidType(Oid id)
Definition: parse_type.c:576
int location
Definition: primnodes.h:905
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409
int location
Definition: primnodes.h:822
bool constisnull
Definition: primnodes.h:215

◆ enforce_generic_type_consistency()

Oid enforce_generic_type_consistency ( const Oid actual_arg_types,
Oid declared_arg_types,
int  nargs,
Oid  rettype,
bool  allow_poly 
)

Definition at line 1881 of file parse_coerce.c.

References Assert, ereport, errcode(), errdetail(), errmsg(), errmsg_internal(), ERROR, format_type_be(), FUNC_MAX_ARGS, get_array_type(), get_element_type(), get_range_subtype(), getBaseType(), InvalidOid, OidIsValid, select_common_type_from_oids(), type_is_array_domain, and type_is_enum().

Referenced by lookup_agg_function(), make_op(), make_scalar_array_op(), ParseFuncOrColumn(), recheck_cast_function_args(), and resolve_aggregate_transtype().

1886 {
1887  bool have_poly_anycompatible = false;
1888  bool have_poly_unknowns = false;
1889  Oid elem_typeid = InvalidOid;
1890  Oid array_typeid = InvalidOid;
1891  Oid range_typeid = InvalidOid;
1892  Oid anycompatible_typeid = InvalidOid;
1893  Oid anycompatible_array_typeid = InvalidOid;
1894  Oid anycompatible_range_typeid = InvalidOid;
1895  Oid anycompatible_range_typelem = InvalidOid;
1896  bool have_anynonarray = (rettype == ANYNONARRAYOID);
1897  bool have_anyenum = (rettype == ANYENUMOID);
1898  bool have_anycompatible_nonarray = (rettype == ANYCOMPATIBLENONARRAYOID);
1899  bool have_anycompatible_array = (rettype == ANYCOMPATIBLEARRAYOID);
1900  bool have_anycompatible_range = (rettype == ANYCOMPATIBLERANGEOID);
1901  int n_poly_args = 0; /* this counts all family-1 arguments */
1902  int n_anycompatible_args = 0; /* this counts only non-unknowns */
1903  Oid anycompatible_actual_types[FUNC_MAX_ARGS];
1904 
1905  /*
1906  * Loop through the arguments to see if we have any that are polymorphic.
1907  * If so, require the actual types to be consistent.
1908  */
1909  Assert(nargs <= FUNC_MAX_ARGS);
1910  for (int j = 0; j < nargs; j++)
1911  {
1912  Oid decl_type = declared_arg_types[j];
1913  Oid actual_type = actual_arg_types[j];
1914 
1915  if (decl_type == ANYELEMENTOID ||
1916  decl_type == ANYNONARRAYOID ||
1917  decl_type == ANYENUMOID)
1918  {
1919  n_poly_args++;
1920  if (decl_type == ANYNONARRAYOID)
1921  have_anynonarray = true;
1922  else if (decl_type == ANYENUMOID)
1923  have_anyenum = true;
1924  if (actual_type == UNKNOWNOID)
1925  {
1926  have_poly_unknowns = true;
1927  continue;
1928  }
1929  if (allow_poly && decl_type == actual_type)
1930  continue; /* no new information here */
1931  if (OidIsValid(elem_typeid) && actual_type != elem_typeid)
1932  ereport(ERROR,
1933  (errcode(ERRCODE_DATATYPE_MISMATCH),
1934  errmsg("arguments declared \"anyelement\" are not all alike"),
1935  errdetail("%s versus %s",
1936  format_type_be(elem_typeid),
1937  format_type_be(actual_type))));
1938  elem_typeid = actual_type;
1939  }
1940  else if (decl_type == ANYARRAYOID)
1941  {
1942  n_poly_args++;
1943  if (actual_type == UNKNOWNOID)
1944  {
1945  have_poly_unknowns = true;
1946  continue;
1947  }
1948  if (allow_poly && decl_type == actual_type)
1949  continue; /* no new information here */
1950  actual_type = getBaseType(actual_type); /* flatten domains */
1951  if (OidIsValid(array_typeid) && actual_type != array_typeid)
1952  ereport(ERROR,
1953  (errcode(ERRCODE_DATATYPE_MISMATCH),
1954  errmsg("arguments declared \"anyarray\" are not all alike"),
1955  errdetail("%s versus %s",
1956  format_type_be(array_typeid),
1957  format_type_be(actual_type))));
1958  array_typeid = actual_type;
1959  }
1960  else if (decl_type == ANYRANGEOID)
1961  {
1962  n_poly_args++;
1963  if (actual_type == UNKNOWNOID)
1964  {
1965  have_poly_unknowns = true;
1966  continue;
1967  }
1968  if (allow_poly && decl_type == actual_type)
1969  continue; /* no new information here */
1970  actual_type = getBaseType(actual_type); /* flatten domains */
1971  if (OidIsValid(range_typeid) && actual_type != range_typeid)
1972  ereport(ERROR,
1973  (errcode(ERRCODE_DATATYPE_MISMATCH),
1974  errmsg("arguments declared \"anyrange\" are not all alike"),
1975  errdetail("%s versus %s",
1976  format_type_be(range_typeid),
1977  format_type_be(actual_type))));
1978  range_typeid = actual_type;
1979  }
1980  else if (decl_type == ANYCOMPATIBLEOID ||
1981  decl_type == ANYCOMPATIBLENONARRAYOID)
1982  {
1983  have_poly_anycompatible = true;
1984  if (decl_type == ANYCOMPATIBLENONARRAYOID)
1985  have_anycompatible_nonarray = true;
1986  if (actual_type == UNKNOWNOID)
1987  continue;
1988  if (allow_poly && decl_type == actual_type)
1989  continue; /* no new information here */
1990  /* collect the actual types of non-unknown COMPATIBLE args */
1991  anycompatible_actual_types[n_anycompatible_args++] = actual_type;
1992  }
1993  else if (decl_type == ANYCOMPATIBLEARRAYOID)
1994  {
1995  Oid anycompatible_elem_type;
1996 
1997  have_poly_anycompatible = true;
1998  have_anycompatible_array = true;
1999  if (actual_type == UNKNOWNOID)
2000  continue;
2001  if (allow_poly && decl_type == actual_type)
2002  continue; /* no new information here */
2003  actual_type = getBaseType(actual_type); /* flatten domains */
2004  anycompatible_elem_type = get_element_type(actual_type);
2005  if (!OidIsValid(anycompatible_elem_type))
2006  ereport(ERROR,
2007  (errcode(ERRCODE_DATATYPE_MISMATCH),
2008  errmsg("argument declared %s is not an array but type %s",
2009  "anycompatiblearray",
2010  format_type_be(actual_type))));
2011  /* collect the element type for common-supertype choice */
2012  anycompatible_actual_types[n_anycompatible_args++] = anycompatible_elem_type;
2013  }
2014  else if (decl_type == ANYCOMPATIBLERANGEOID)
2015  {
2016  have_poly_anycompatible = true;
2017  have_anycompatible_range = true;
2018  if (actual_type == UNKNOWNOID)
2019  continue;
2020  if (allow_poly && decl_type == actual_type)
2021  continue; /* no new information here */
2022  actual_type = getBaseType(actual_type); /* flatten domains */
2023  if (OidIsValid(anycompatible_range_typeid))
2024  {
2025  /* All ANYCOMPATIBLERANGE arguments must be the same type */
2026  if (anycompatible_range_typeid != actual_type)
2027  ereport(ERROR,
2028  (errcode(ERRCODE_DATATYPE_MISMATCH),
2029  errmsg("arguments declared \"anycompatiblerange\" are not all alike"),
2030  errdetail("%s versus %s",
2031  format_type_be(anycompatible_range_typeid),
2032  format_type_be(actual_type))));
2033  }
2034  else
2035  {
2036  anycompatible_range_typeid = actual_type;
2037  anycompatible_range_typelem = get_range_subtype(actual_type);
2038  if (!OidIsValid(anycompatible_range_typelem))
2039  ereport(ERROR,
2040  (errcode(ERRCODE_DATATYPE_MISMATCH),
2041  errmsg("argument declared %s is not a range type but type %s",
2042  "anycompatiblerange",
2043  format_type_be(actual_type))));
2044  /* collect the subtype for common-supertype choice */
2045  anycompatible_actual_types[n_anycompatible_args++] = anycompatible_range_typelem;
2046  }
2047  }
2048  }
2049 
2050  /*
2051  * Fast Track: if none of the arguments are polymorphic, return the
2052  * unmodified rettype. Not our job to resolve it if it's polymorphic.
2053  */
2054  if (n_poly_args == 0 && !have_poly_anycompatible)
2055  return rettype;
2056 
2057  /* Check matching of family-1 polymorphic arguments, if any */
2058  if (n_poly_args)
2059  {
2060  /* Get the element type based on the array type, if we have one */
2061  if (OidIsValid(array_typeid))
2062  {
2063  Oid array_typelem;
2064 
2065  if (array_typeid == ANYARRAYOID)
2066  {
2067  /*
2068  * Special case for matching ANYARRAY input to an ANYARRAY
2069  * argument: allow it iff no other arguments are family-1
2070  * polymorphics (otherwise we couldn't be sure whether the
2071  * array element type matches up) and the result type doesn't
2072  * require us to infer a specific element type.
2073  */
2074  if (n_poly_args != 1 ||
2075  (rettype != ANYARRAYOID &&
2076  IsPolymorphicTypeFamily1(rettype)))
2077  ereport(ERROR,
2078  (errcode(ERRCODE_DATATYPE_MISMATCH),
2079  errmsg("cannot determine element type of \"anyarray\" argument")));
2080  array_typelem = ANYELEMENTOID;
2081  }
2082  else
2083  {
2084  array_typelem = get_element_type(array_typeid);
2085  if (!OidIsValid(array_typelem))
2086  ereport(ERROR,
2087  (errcode(ERRCODE_DATATYPE_MISMATCH),
2088  errmsg("argument declared %s is not an array but type %s",
2089  "anyarray", format_type_be(array_typeid))));
2090  }
2091 
2092  if (!OidIsValid(elem_typeid))
2093  {
2094  /*
2095  * if we don't have an element type yet, use the one we just
2096  * got
2097  */
2098  elem_typeid = array_typelem;
2099  }
2100  else if (array_typelem != elem_typeid)
2101  {
2102  /* otherwise, they better match */
2103  ereport(ERROR,
2104  (errcode(ERRCODE_DATATYPE_MISMATCH),
2105  errmsg("argument declared %s is not consistent with argument declared %s",
2106  "anyarray", "anyelement"),
2107  errdetail("%s versus %s",
2108  format_type_be(array_typeid),
2109  format_type_be(elem_typeid))));
2110  }
2111  }
2112 
2113  /* Get the element type based on the range type, if we have one */
2114  if (OidIsValid(range_typeid))
2115  {
2116  Oid range_typelem;
2117 
2118  range_typelem = get_range_subtype(range_typeid);
2119  if (!OidIsValid(range_typelem))
2120  ereport(ERROR,
2121  (errcode(ERRCODE_DATATYPE_MISMATCH),
2122  errmsg("argument declared %s is not a range type but type %s",
2123  "anyrange",
2124  format_type_be(range_typeid))));
2125 
2126  if (!OidIsValid(elem_typeid))
2127  {
2128  /*
2129  * if we don't have an element type yet, use the one we just
2130  * got
2131  */
2132  elem_typeid = range_typelem;
2133  }
2134  else if (range_typelem != elem_typeid)
2135  {
2136  /* otherwise, they better match */
2137  ereport(ERROR,
2138  (errcode(ERRCODE_DATATYPE_MISMATCH),
2139  errmsg("argument declared %s is not consistent with argument declared %s",
2140  "anyrange", "anyelement"),
2141  errdetail("%s versus %s",
2142  format_type_be(range_typeid),
2143  format_type_be(elem_typeid))));
2144  }
2145  }
2146 
2147  if (!OidIsValid(elem_typeid))
2148  {
2149  if (allow_poly)
2150  {
2151  elem_typeid = ANYELEMENTOID;
2152  array_typeid = ANYARRAYOID;
2153  range_typeid = ANYRANGEOID;
2154  }
2155  else
2156  {
2157  /*
2158  * Only way to get here is if all the family-1 polymorphic
2159  * arguments have UNKNOWN inputs.
2160  */
2161  ereport(ERROR,
2162  (errcode(ERRCODE_DATATYPE_MISMATCH),
2163  errmsg("could not determine polymorphic type because input has type %s",
2164  "unknown")));
2165  }
2166  }
2167 
2168  if (have_anynonarray && elem_typeid != ANYELEMENTOID)
2169  {
2170  /*
2171  * require the element type to not be an array or domain over
2172  * array
2173  */
2174  if (type_is_array_domain(elem_typeid))
2175  ereport(ERROR,
2176  (errcode(ERRCODE_DATATYPE_MISMATCH),
2177  errmsg("type matched to anynonarray is an array type: %s",
2178  format_type_be(elem_typeid))));
2179  }
2180 
2181  if (have_anyenum && elem_typeid != ANYELEMENTOID)
2182  {
2183  /* require the element type to be an enum */
2184  if (!type_is_enum(elem_typeid))
2185  ereport(ERROR,
2186  (errcode(ERRCODE_DATATYPE_MISMATCH),
2187  errmsg("type matched to anyenum is not an enum type: %s",
2188  format_type_be(elem_typeid))));
2189  }
2190  }
2191 
2192  /* Check matching of family-2 polymorphic arguments, if any */
2193  if (have_poly_anycompatible)
2194  {
2195  if (n_anycompatible_args > 0)
2196  {
2197  anycompatible_typeid =
2198  select_common_type_from_oids(n_anycompatible_args,
2199  anycompatible_actual_types,
2200  false);
2201 
2202  if (have_anycompatible_array)
2203  {
2204  anycompatible_array_typeid = get_array_type(anycompatible_typeid);
2205  if (!OidIsValid(anycompatible_array_typeid))
2206  ereport(ERROR,
2207  (errcode(ERRCODE_UNDEFINED_OBJECT),
2208  errmsg("could not find array type for data type %s",
2209  format_type_be(anycompatible_typeid))));
2210  }
2211 
2212  if (have_anycompatible_range)
2213  {
2214  /* we can't infer a range type from the others */
2215  if (!OidIsValid(anycompatible_range_typeid))
2216  ereport(ERROR,
2217  (errcode(ERRCODE_DATATYPE_MISMATCH),
2218  errmsg("could not determine polymorphic type %s because input has type %s",
2219  "anycompatiblerange", "unknown")));
2220 
2221  /*
2222  * the anycompatible type must exactly match the range element
2223  * type
2224  */
2225  if (anycompatible_range_typelem != anycompatible_typeid)
2226  ereport(ERROR,
2227  (errcode(ERRCODE_DATATYPE_MISMATCH),
2228  errmsg("anycompatiblerange type %s does not match anycompatible type %s",
2229  format_type_be(anycompatible_range_typeid),
2230  format_type_be(anycompatible_typeid))));
2231  }
2232 
2233  if (have_anycompatible_nonarray)
2234  {
2235  /*
2236  * require the element type to not be an array or domain over
2237  * array
2238  */
2239  if (type_is_array_domain(anycompatible_typeid))
2240  ereport(ERROR,
2241  (errcode(ERRCODE_DATATYPE_MISMATCH),
2242  errmsg("type matched to anycompatiblenonarray is an array type: %s",
2243  format_type_be(anycompatible_typeid))));
2244  }
2245  }
2246  else
2247  {
2248  if (allow_poly)
2249  {
2250  anycompatible_typeid = ANYCOMPATIBLEOID;
2251  anycompatible_array_typeid = ANYCOMPATIBLEARRAYOID;
2252  anycompatible_range_typeid = ANYCOMPATIBLERANGEOID;
2253  }
2254  else
2255  {
2256  /*
2257  * Only way to get here is if all the family-2 polymorphic
2258  * arguments have UNKNOWN inputs. Resolve to TEXT as
2259  * select_common_type() would do. That doesn't license us to
2260  * use TEXTRANGE, though.
2261  */
2262  anycompatible_typeid = TEXTOID;
2263  anycompatible_array_typeid = TEXTARRAYOID;
2264  if (have_anycompatible_range)
2265  ereport(ERROR,
2266  (errcode(ERRCODE_DATATYPE_MISMATCH),
2267  errmsg("could not determine polymorphic type %s because input has type %s",
2268  "anycompatiblerange", "unknown")));
2269  }
2270  }
2271 
2272  /* replace family-2 polymorphic types by selected types */
2273  for (int j = 0; j < nargs; j++)
2274  {
2275  Oid decl_type = declared_arg_types[j];
2276 
2277  if (decl_type == ANYCOMPATIBLEOID ||
2278  decl_type == ANYCOMPATIBLENONARRAYOID)
2279  declared_arg_types[j] = anycompatible_typeid;
2280  else if (decl_type == ANYCOMPATIBLEARRAYOID)
2281  declared_arg_types[j] = anycompatible_array_typeid;
2282  else if (decl_type == ANYCOMPATIBLERANGEOID)
2283  declared_arg_types[j] = anycompatible_range_typeid;
2284  }
2285  }
2286 
2287  /*
2288  * If we had any UNKNOWN inputs for family-1 polymorphic arguments,
2289  * re-scan to assign correct types to them.
2290  *
2291  * Note: we don't have to consider unknown inputs that were matched to
2292  * family-2 polymorphic arguments, because we forcibly updated their
2293  * declared_arg_types[] positions just above.
2294  */
2295  if (have_poly_unknowns)
2296  {
2297  for (int j = 0; j < nargs; j++)
2298  {
2299  Oid decl_type = declared_arg_types[j];
2300  Oid actual_type = actual_arg_types[j];
2301 
2302  if (actual_type != UNKNOWNOID)
2303  continue;
2304 
2305  if (decl_type == ANYELEMENTOID ||
2306  decl_type == ANYNONARRAYOID ||
2307  decl_type == ANYENUMOID)
2308  declared_arg_types[j] = elem_typeid;
2309  else if (decl_type == ANYARRAYOID)
2310  {
2311  if (!OidIsValid(array_typeid))
2312  {
2313  array_typeid = get_array_type(elem_typeid);
2314  if (!OidIsValid(array_typeid))
2315  ereport(ERROR,
2316  (errcode(ERRCODE_UNDEFINED_OBJECT),
2317  errmsg("could not find array type for data type %s",
2318  format_type_be(elem_typeid))));
2319  }
2320  declared_arg_types[j] = array_typeid;
2321  }
2322  else if (decl_type == ANYRANGEOID)
2323  {
2324  if (!OidIsValid(range_typeid))
2325  {
2326  /* we can't infer a range type from the others */
2327  ereport(ERROR,
2328  (errcode(ERRCODE_DATATYPE_MISMATCH),
2329  errmsg("could not determine polymorphic type %s because input has type %s",
2330  "anyrange", "unknown")));
2331  }
2332  declared_arg_types[j] = range_typeid;
2333  }
2334  }
2335  }
2336 
2337  /* if we return ANYELEMENT use the appropriate argument type */
2338  if (rettype == ANYELEMENTOID ||
2339  rettype == ANYNONARRAYOID ||
2340  rettype == ANYENUMOID)
2341  return elem_typeid;
2342 
2343  /* if we return ANYARRAY use the appropriate argument type */
2344  if (rettype == ANYARRAYOID)
2345  {
2346  if (!OidIsValid(array_typeid))
2347  {
2348  array_typeid = get_array_type(elem_typeid);
2349  if (!OidIsValid(array_typeid))
2350  ereport(ERROR,
2351  (errcode(ERRCODE_UNDEFINED_OBJECT),
2352  errmsg("could not find array type for data type %s",
2353  format_type_be(elem_typeid))));
2354  }
2355  return array_typeid;
2356  }
2357 
2358  /* if we return ANYRANGE use the appropriate argument type */
2359  if (rettype == ANYRANGEOID)
2360  {
2361  /* this error is unreachable if the function signature is valid: */
2362  if (!OidIsValid(range_typeid))
2363  ereport(ERROR,
2364  (errcode(ERRCODE_DATATYPE_MISMATCH),
2365  errmsg("could not determine polymorphic type %s because input has type %s",
2366  "anyrange", "unknown")));
2367  return range_typeid;
2368  }
2369 
2370  /* if we return ANYCOMPATIBLE use the appropriate type */
2371  if (rettype == ANYCOMPATIBLEOID ||
2372  rettype == ANYCOMPATIBLENONARRAYOID)
2373  {
2374  /* this error is unreachable if the function signature is valid: */
2375  if (!OidIsValid(anycompatible_typeid))
2376  ereport(ERROR,
2377  (errcode(ERRCODE_DATATYPE_MISMATCH),
2378  errmsg_internal("could not identify anycompatible type")));
2379  return anycompatible_typeid;
2380  }
2381 
2382  /* if we return ANYCOMPATIBLEARRAY use the appropriate type */
2383  if (rettype == ANYCOMPATIBLEARRAYOID)
2384  {
2385  /* this error is unreachable if the function signature is valid: */
2386  if (!OidIsValid(anycompatible_array_typeid))
2387  ereport(ERROR,
2388  (errcode(ERRCODE_DATATYPE_MISMATCH),
2389  errmsg_internal("could not identify anycompatiblearray type")));
2390  return anycompatible_array_typeid;
2391  }
2392 
2393  /* if we return ANYCOMPATIBLERANGE use the appropriate argument type */
2394  if (rettype == ANYCOMPATIBLERANGEOID)
2395  {
2396  /* this error is unreachable if the function signature is valid: */
2397  if (!OidIsValid(anycompatible_range_typeid))
2398  ereport(ERROR,
2399  (errcode(ERRCODE_DATATYPE_MISMATCH),
2400  errmsg_internal("could not identify anycompatiblerange type")));
2401  return anycompatible_range_typeid;
2402  }
2403 
2404  /* we don't return a generic type; send back the original return type */
2405  return rettype;
2406 }
#define type_is_array_domain(typid)
Definition: lsyscache.h:193
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2636
Oid get_array_type(Oid typid)
Definition: lsyscache.c:2664
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:652
static Oid select_common_type_from_oids(int nargs, const Oid *typeids, bool noerror)
#define FUNC_MAX_ARGS
#define ERROR
Definition: elog.h:43
int errdetail(const char *fmt,...)
Definition: elog.c:954
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg_internal(const char *fmt,...)
Definition: elog.c:908
#define Assert(condition)
Definition: c.h:746
bool type_is_enum(Oid typid)
Definition: lsyscache.c:2566
int errmsg(const char *fmt,...)
Definition: elog.c:821
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409
Oid get_range_subtype(Oid rangeOid)
Definition: lsyscache.c:3232

◆ find_coercion_pathway()

CoercionPathType find_coercion_pathway ( Oid  targetTypeId,
Oid  sourceTypeId,
CoercionContext  ccontext,
Oid funcid 
)

Definition at line 2651 of file parse_coerce.c.

References CASTSOURCETARGET, COERCION_ASSIGNMENT, COERCION_EXPLICIT, COERCION_IMPLICIT, COERCION_PATH_ARRAYCOERCE, COERCION_PATH_COERCEVIAIO, COERCION_PATH_FUNC, COERCION_PATH_NONE, COERCION_PATH_RELABELTYPE, elog, ERROR, find_coercion_pathway(), get_element_type(), getBaseType(), GETSTRUCT, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum, OidIsValid, ReleaseSysCache(), SearchSysCache2(), and TypeCategory().

Referenced by can_coerce_type(), coerce_type(), find_coercion_pathway(), findFkeyCast(), func_get_detail(), json_categorize_type(), jsonb_categorize_type(), and ri_HashCompareOp().

2654 {
2656  HeapTuple tuple;
2657 
2658  *funcid = InvalidOid;
2659 
2660  /* Perhaps the types are domains; if so, look at their base types */
2661  if (OidIsValid(sourceTypeId))
2662  sourceTypeId = getBaseType(sourceTypeId);
2663  if (OidIsValid(targetTypeId))
2664  targetTypeId = getBaseType(targetTypeId);
2665 
2666  /* Domains are always coercible to and from their base type */
2667  if (sourceTypeId == targetTypeId)
2669 
2670  /* Look in pg_cast */
2672  ObjectIdGetDatum(sourceTypeId),
2673  ObjectIdGetDatum(targetTypeId));
2674 
2675  if (HeapTupleIsValid(tuple))
2676  {
2677  Form_pg_cast castForm = (Form_pg_cast) GETSTRUCT(tuple);
2678  CoercionContext castcontext;
2679 
2680  /* convert char value for castcontext to CoercionContext enum */
2681  switch (castForm->castcontext)
2682  {
2683  case COERCION_CODE_IMPLICIT:
2684  castcontext = COERCION_IMPLICIT;
2685  break;
2686  case COERCION_CODE_ASSIGNMENT:
2687  castcontext = COERCION_ASSIGNMENT;
2688  break;
2689  case COERCION_CODE_EXPLICIT:
2690  castcontext = COERCION_EXPLICIT;
2691  break;
2692  default:
2693  elog(ERROR, "unrecognized castcontext: %d",
2694  (int) castForm->castcontext);
2695  castcontext = 0; /* keep compiler quiet */
2696  break;
2697  }
2698 
2699  /* Rely on ordering of enum for correct behavior here */
2700  if (ccontext >= castcontext)
2701  {
2702  switch (castForm->castmethod)
2703  {
2704  case COERCION_METHOD_FUNCTION:
2705  result = COERCION_PATH_FUNC;
2706  *funcid = castForm->castfunc;
2707  break;
2708  case COERCION_METHOD_INOUT:
2709  result = COERCION_PATH_COERCEVIAIO;
2710  break;
2711  case COERCION_METHOD_BINARY:
2712  result = COERCION_PATH_RELABELTYPE;
2713  break;
2714  default:
2715  elog(ERROR, "unrecognized castmethod: %d",
2716  (int) castForm->castmethod);
2717  break;
2718  }
2719  }
2720 
2721  ReleaseSysCache(tuple);
2722  }
2723  else
2724  {
2725  /*
2726  * If there's no pg_cast entry, perhaps we are dealing with a pair of
2727  * array types. If so, and if their element types have a conversion
2728  * pathway, report that we can coerce with an ArrayCoerceExpr.
2729  *
2730  * Hack: disallow coercions to oidvector and int2vector, which
2731  * otherwise tend to capture coercions that should go to "real" array
2732  * types. We want those types to be considered "real" arrays for many
2733  * purposes, but not this one. (Also, ArrayCoerceExpr isn't
2734  * guaranteed to produce an output that meets the restrictions of
2735  * these datatypes, such as being 1-dimensional.)
2736  */
2737  if (targetTypeId != OIDVECTOROID && targetTypeId != INT2VECTOROID)
2738  {
2739  Oid targetElem;
2740  Oid sourceElem;
2741 
2742  if ((targetElem = get_element_type(targetTypeId)) != InvalidOid &&
2743  (sourceElem = get_element_type(sourceTypeId)) != InvalidOid)
2744  {
2745  CoercionPathType elempathtype;
2746  Oid elemfuncid;
2747 
2748  elempathtype = find_coercion_pathway(targetElem,
2749  sourceElem,
2750  ccontext,
2751  &elemfuncid);
2752  if (elempathtype != COERCION_PATH_NONE)
2753  {
2754  result = COERCION_PATH_ARRAYCOERCE;
2755  }
2756  }
2757  }
2758 
2759  /*
2760  * If we still haven't found a possibility, consider automatic casting
2761  * using I/O functions. We allow assignment casts to string types and
2762  * explicit casts from string types to be handled this way. (The
2763  * CoerceViaIO mechanism is a lot more general than that, but this is
2764  * all we want to allow in the absence of a pg_cast entry.) It would
2765  * probably be better to insist on explicit casts in both directions,
2766  * but this is a compromise to preserve something of the pre-8.3
2767  * behavior that many types had implicit (yipes!) casts to text.
2768  */
2769  if (result == COERCION_PATH_NONE)
2770  {
2771  if (ccontext >= COERCION_ASSIGNMENT &&
2772  TypeCategory(targetTypeId) == TYPCATEGORY_STRING)
2773  result = COERCION_PATH_COERCEVIAIO;
2774  else if (ccontext >= COERCION_EXPLICIT &&
2775  TypeCategory(sourceTypeId) == TYPCATEGORY_STRING)
2776  result = COERCION_PATH_COERCEVIAIO;
2777  }
2778  }
2779 
2780  return result;
2781 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Oid get_element_type(Oid typid)
Definition: lsyscache.c:2636
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:652
CoercionContext
Definition: primnodes.h:440
CoercionPathType
Definition: parse_coerce.h:24
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
TYPCATEGORY TypeCategory(Oid type)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1127
CoercionPathType find_coercion_pathway(Oid targetTypeId, Oid sourceTypeId, CoercionContext ccontext, Oid *funcid)
#define elog(elevel,...)
Definition: elog.h:214
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409

◆ find_typmod_coercion_function()

CoercionPathType find_typmod_coercion_function ( Oid  typeId,
Oid funcid 
)

Definition at line 2806 of file parse_coerce.c.

References CASTSOURCETARGET, COERCION_PATH_ARRAYCOERCE, COERCION_PATH_FUNC, COERCION_PATH_NONE, GETSTRUCT, HeapTupleIsValid, InvalidOid, ObjectIdGetDatum, OidIsValid, ReleaseSysCache(), SearchSysCache2(), and typeidType().

Referenced by coerce_type_typmod().

2808 {
2809  CoercionPathType result;
2810  Type targetType;
2811  Form_pg_type typeForm;
2812  HeapTuple tuple;
2813 
2814  *funcid = InvalidOid;
2815  result = COERCION_PATH_FUNC;
2816 
2817  targetType = typeidType(typeId);
2818  typeForm = (Form_pg_type) GETSTRUCT(targetType);
2819 
2820  /* Check for a varlena array type */
2821  if (typeForm->typelem != InvalidOid && typeForm->typlen == -1)
2822  {
2823  /* Yes, switch our attention to the element type */
2824  typeId = typeForm->typelem;
2825  result = COERCION_PATH_ARRAYCOERCE;
2826  }
2827  ReleaseSysCache(targetType);
2828 
2829  /* Look in pg_cast */
2831  ObjectIdGetDatum(typeId),
2832  ObjectIdGetDatum(typeId));
2833 
2834  if (HeapTupleIsValid(tuple))
2835  {
2836  Form_pg_cast castForm = (Form_pg_cast) GETSTRUCT(tuple);
2837 
2838  *funcid = castForm->castfunc;
2839  ReleaseSysCache(tuple);
2840  }
2841 
2842  if (!OidIsValid(*funcid))
2843  result = COERCION_PATH_NONE;
2844 
2845  return result;
2846 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define OidIsValid(objectId)
Definition: c.h:652
CoercionPathType
Definition: parse_coerce.h:24
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:255
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1127
Type typeidType(Oid id)
Definition: parse_type.c:576

◆ IsBinaryCoercible()

bool IsBinaryCoercible ( Oid  srctype,
Oid  targettype 
)

Definition at line 2554 of file parse_coerce.c.

References CASTSOURCETARGET, getBaseType(), GETSTRUCT, HeapTupleIsValid, is_complex_array(), ISCOMPLEX, ObjectIdGetDatum, OidIsValid, ReleaseSysCache(), SearchSysCache2(), type_is_array, type_is_enum(), and type_is_range().

Referenced by AggregateCreate(), build_pertrans_for_aggref(), check_amproc_signature(), check_hash_func_signature(), compatible_oper(), CreateCast(), findRangeSubOpclass(), GetDefaultOpClass(), initialize_peragg(), lookup_agg_function(), ResolveOpClass(), ri_HashCompareOp(), satisfies_hash_partition(), ts_stat_sql(), tsvector_update_trigger(), and tupledesc_match().

2555 {
2556  HeapTuple tuple;
2557  Form_pg_cast castForm;
2558  bool result;
2559 
2560  /* Fast path if same type */
2561  if (srctype == targettype)
2562  return true;
2563 
2564  /* Anything is coercible to ANY or ANYELEMENT or ANYCOMPATIBLE */
2565  if (targettype == ANYOID || targettype == ANYELEMENTOID ||
2566  targettype == ANYCOMPATIBLEOID)
2567  return true;
2568 
2569  /* If srctype is a domain, reduce to its base type */
2570  if (OidIsValid(srctype))
2571  srctype = getBaseType(srctype);
2572 
2573  /* Somewhat-fast path for domain -> base type case */
2574  if (srctype == targettype)
2575  return true;
2576 
2577  /* Also accept any array type as coercible to ANY[COMPATIBLE]ARRAY */
2578  if (targettype == ANYARRAYOID || targettype == ANYCOMPATIBLEARRAYOID)
2579  if (type_is_array(srctype))
2580  return true;
2581 
2582  /* Also accept any non-array type as coercible to ANY[COMPATIBLE]NONARRAY */
2583  if (targettype == ANYNONARRAYOID || targettype == ANYCOMPATIBLENONARRAYOID)
2584  if (!type_is_array(srctype))
2585  return true;
2586 
2587  /* Also accept any enum type as coercible to ANYENUM */
2588  if (targettype == ANYENUMOID)
2589  if (type_is_enum(srctype))
2590  return true;
2591 
2592  /* Also accept any range type as coercible to ANY[COMPATIBLE]RANGE */
2593  if (targettype == ANYRANGEOID || targettype == ANYCOMPATIBLERANGEOID)
2594  if (type_is_range(srctype))
2595  return true;
2596 
2597  /* Also accept any composite type as coercible to RECORD */
2598  if (targettype == RECORDOID)
2599  if (ISCOMPLEX(srctype))
2600  return true;
2601 
2602  /* Also accept any composite array type as coercible to RECORD[] */
2603  if (targettype == RECORDARRAYOID)
2604  if (is_complex_array(srctype))
2605  return true;
2606 
2607  /* Else look in pg_cast */
2609  ObjectIdGetDatum(srctype),
2610  ObjectIdGetDatum(targettype));
2611  if (!HeapTupleIsValid(tuple))
2612  return false; /* no cast */
2613  castForm = (Form_pg_cast) GETSTRUCT(tuple);
2614 
2615  result = (castForm->castmethod == COERCION_METHOD_BINARY &&
2616  castForm->castcontext == COERCION_CODE_IMPLICIT);
2617 
2618  ReleaseSysCache(tuple);
2619 
2620  return result;
2621 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool type_is_range(Oid typid)
Definition: lsyscache.c:2576
#define OidIsValid(objectId)
Definition: c.h:652
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define ISCOMPLEX(typeid)
Definition: parse_type.h:58
bool type_is_enum(Oid typid)
Definition: lsyscache.c:2566
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1127
#define type_is_array(typid)
Definition: lsyscache.h:191
static bool is_complex_array(Oid typid)
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409

◆ IsPreferredType()

bool IsPreferredType ( TYPCATEGORY  category,
Oid  type 
)

Definition at line 2519 of file parse_coerce.c.

References get_type_category_preferred().

Referenced by func_select_candidate(), and GetDefaultOpClass().

2520 {
2521  char typcategory;
2522  bool typispreferred;
2523 
2524  get_type_category_preferred(type, &typcategory, &typispreferred);
2525  if (category == typcategory || category == TYPCATEGORY_INVALID)
2526  return typispreferred;
2527  else
2528  return false;
2529 }
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
Definition: lsyscache.c:2588

◆ parser_coercion_errposition()

int parser_coercion_errposition ( ParseState pstate,
int  coerce_location,
Node input_expr 
)

Definition at line 1251 of file parse_coerce.c.

References exprLocation(), and parser_errposition().

Referenced by coerce_record_to_complex(), and transformTypeCast().

1254 {
1255  if (coerce_location >= 0)
1256  return parser_errposition(pstate, coerce_location);
1257  else
1258  return parser_errposition(pstate, exprLocation(input_expr));
1259 }
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1240
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110

◆ select_common_type()

Oid select_common_type ( ParseState pstate,
List exprs,
const char *  context,
Node **  which_expr 
)

Definition at line 1277 of file parse_coerce.c.

References Assert, can_coerce_type(), COERCION_IMPLICIT, ereport, errcode(), errmsg(), ERROR, exprLocation(), exprType(), for_each_cell, format_type_be(), get_type_category_preferred(), getBaseType(), InvalidOid, lfirst, linitial, list_second_cell(), NIL, and parser_errposition().

Referenced by buildMergedJoinVar(), transformAExprIn(), transformArrayExpr(), transformCaseExpr(), transformCoalesceExpr(), transformMinMaxExpr(), transformSetOperationTree(), transformValuesClause(), and unify_hypothetical_args().

1279 {
1280  Node *pexpr;
1281  Oid ptype;
1282  TYPCATEGORY pcategory;
1283  bool pispreferred;
1284  ListCell *lc;
1285 
1286  Assert(exprs != NIL);
1287  pexpr = (Node *) linitial(exprs);
1288  lc = list_second_cell(exprs);
1289  ptype = exprType(pexpr);
1290 
1291  /*
1292  * If all input types are valid and exactly the same, just pick that type.
1293  * This is the only way that we will resolve the result as being a domain
1294  * type; otherwise domains are smashed to their base types for comparison.
1295  */
1296  if (ptype != UNKNOWNOID)
1297  {
1298  for_each_cell(lc, exprs, lc)
1299  {
1300  Node *nexpr = (Node *) lfirst(lc);
1301  Oid ntype = exprType(nexpr);
1302 
1303  if (ntype != ptype)
1304  break;
1305  }
1306  if (lc == NULL) /* got to the end of the list? */
1307  {
1308  if (which_expr)
1309  *which_expr = pexpr;
1310  return ptype;
1311  }
1312  }
1313 
1314  /*
1315  * Nope, so set up for the full algorithm. Note that at this point, lc
1316  * points to the first list item with type different from pexpr's; we need
1317  * not re-examine any items the previous loop advanced over.
1318  */
1319  ptype = getBaseType(ptype);
1320  get_type_category_preferred(ptype, &pcategory, &pispreferred);
1321 
1322  for_each_cell(lc, exprs, lc)
1323  {
1324  Node *nexpr = (Node *) lfirst(lc);
1325  Oid ntype = getBaseType(exprType(nexpr));
1326 
1327  /* move on to next one if no new information... */
1328  if (ntype != UNKNOWNOID && ntype != ptype)
1329  {
1330  TYPCATEGORY ncategory;
1331  bool nispreferred;
1332 
1333  get_type_category_preferred(ntype, &ncategory, &nispreferred);
1334  if (ptype == UNKNOWNOID)
1335  {
1336  /* so far, only unknowns so take anything... */
1337  pexpr = nexpr;
1338  ptype = ntype;
1339  pcategory = ncategory;
1340  pispreferred = nispreferred;
1341  }
1342  else if (ncategory != pcategory)
1343  {
1344  /*
1345  * both types in different categories? then not much hope...
1346  */
1347  if (context == NULL)
1348  return InvalidOid;
1349  ereport(ERROR,
1350  (errcode(ERRCODE_DATATYPE_MISMATCH),
1351  /*------
1352  translator: first %s is name of a SQL construct, eg CASE */
1353  errmsg("%s types %s and %s cannot be matched",
1354  context,
1355  format_type_be(ptype),
1356  format_type_be(ntype)),
1357  parser_errposition(pstate, exprLocation(nexpr))));
1358  }
1359  else if (!pispreferred &&
1360  can_coerce_type(1, &ptype, &ntype, COERCION_IMPLICIT) &&
1361  !can_coerce_type(1, &ntype, &ptype, COERCION_IMPLICIT))
1362  {
1363  /*
1364  * take new type if can coerce to it implicitly but not the
1365  * other way; but if we have a preferred type, stay on it.
1366  */
1367  pexpr = nexpr;
1368  ptype = ntype;
1369  pcategory = ncategory;
1370  pispreferred = nispreferred;
1371  }
1372  }
1373  }
1374 
1375  /*
1376  * If all the inputs were UNKNOWN type --- ie, unknown-type literals ---
1377  * then resolve as type TEXT. This situation comes up with constructs
1378  * like SELECT (CASE WHEN foo THEN 'bar' ELSE 'baz' END); SELECT 'foo'
1379  * UNION SELECT 'bar'; It might seem desirable to leave the construct's
1380  * output type as UNKNOWN, but that really doesn't work, because we'd
1381  * probably end up needing a runtime coercion from UNKNOWN to something
1382  * else, and we usually won't have it. We need to coerce the unknown
1383  * literals while they are still literals, so a decision has to be made
1384  * now.
1385  */
1386  if (ptype == UNKNOWNOID)
1387  ptype = TEXTOID;
1388 
1389  if (which_expr)
1390  *which_expr = pexpr;
1391  return ptype;
1392 }
#define NIL
Definition: pg_list.h:65
int exprLocation(const Node *expr)
Definition: nodeFuncs.c:1240
#define for_each_cell(cell, lst, initcell)
Definition: pg_list.h:405
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
Definition: parse_coerce.c:546
Definition: nodes.h:528
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
unsigned int Oid
Definition: postgres_ext.h:31
char TYPCATEGORY
Definition: parse_coerce.h:21
#define linitial(l)
Definition: pg_list.h:174
#define ERROR
Definition: elog.h:43
static ListCell * list_second_cell(const List *l)
Definition: pg_list.h:139
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
#define Assert(condition)
Definition: c.h:746
#define lfirst(lc)
Definition: pg_list.h:169
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:110
int errmsg(const char *fmt,...)
Definition: elog.c:821
Oid getBaseType(Oid typid)
Definition: lsyscache.c:2409
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
Definition: lsyscache.c:2588

◆ TypeCategory()

TYPCATEGORY TypeCategory ( Oid  type)

Definition at line 2500 of file parse_coerce.c.

References Assert, and get_type_category_preferred().

Referenced by find_coercion_pathway(), func_get_detail(), func_select_candidate(), and GetDefaultOpClass().

2501 {
2502  char typcategory;
2503  bool typispreferred;
2504 
2505  get_type_category_preferred(type, &typcategory, &typispreferred);
2506  Assert(typcategory != TYPCATEGORY_INVALID);
2507  return (TYPCATEGORY) typcategory;
2508 }
char TYPCATEGORY
Definition: parse_coerce.h:21
#define Assert(condition)
Definition: c.h:746
void get_type_category_preferred(Oid typid, char *typcategory, bool *typispreferred)
Definition: lsyscache.c:2588