1/*-------------------------------------------------------------------------
2 *
3 * parse_coerce.h
4 * Routines for type coercion.
5 *
6 *
7 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/parser/parse_coerce.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef PARSE_COERCE_H
15#define PARSE_COERCE_H
16
17#include "parser/parse_node.h"
18
19
20/* Type categories (see TYPCATEGORY_xxx symbols in catalog/pg_type.h) */
21typedef char TYPCATEGORY;
22
23/* Result codes for find_coercion_pathway */
24typedef enum CoercionPathType
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 */
31} CoercionPathType;
32
33
34extern bool IsBinaryCoercible(Oid srctype, Oid targettype);
35extern bool IsPreferredType(TYPCATEGORY category, Oid type);
36extern TYPCATEGORY TypeCategory(Oid type);
37
38extern Node *coerce_to_target_type(ParseState *pstate,
39 Node *expr, Oid exprtype,
40 Oid targettype, int32 targettypmod,
41 CoercionContext ccontext,
42 CoercionForm cformat,
43 int location);
44extern bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids,
45 CoercionContext ccontext);
46extern Node *coerce_type(ParseState *pstate, Node *node,
47 Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod,
48 CoercionContext ccontext, CoercionForm cformat, int location);
49extern Node *coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod,
50 Oid typeId,
51 CoercionContext ccontext, CoercionForm cformat, int location,
52 bool hideInputCoercion);
53
54extern Node *coerce_to_boolean(ParseState *pstate, Node *node,
55 const char *constructName);
56extern Node *coerce_to_specific_type(ParseState *pstate, Node *node,
57 Oid targetTypeId,
58 const char *constructName);
59
60extern Node *coerce_to_specific_type_typmod(ParseState *pstate, Node *node,
61 Oid targetTypeId, int32 targetTypmod,
62 const char *constructName);
63
64extern int parser_coercion_errposition(ParseState *pstate,
65 int coerce_location,
66 Node *input_expr);
67
68extern Oid select_common_type(ParseState *pstate, List *exprs,
69 const char *context, Node **which_expr);
70extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
71 Oid targetTypeId,
72 const char *context);
73
74extern bool check_generic_type_consistency(const Oid *actual_arg_types,
75 const Oid *declared_arg_types,
76 int nargs);
77extern Oid enforce_generic_type_consistency(const Oid *actual_arg_types,
78 Oid *declared_arg_types,
79 int nargs,
80 Oid rettype,
81 bool allow_poly);
82extern Oid resolve_generic_type(Oid declared_type,
83 Oid context_actual_type,
84 Oid context_declared_type);
85
86extern CoercionPathType find_coercion_pathway(Oid targetTypeId,
87 Oid sourceTypeId,
88 CoercionContext ccontext,
89 Oid *funcid);
90extern CoercionPathType find_typmod_coercion_function(Oid typeId,
91 Oid *funcid);
92
93#endif /* PARSE_COERCE_H */
94