1 /*-------------------------------------------------------------------------
5 * Routines for type coercion.
7 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: parse_coerce.h,v 1.30 2001/06/23 22:23:49 momjian Exp $
12 *-------------------------------------------------------------------------
14 #ifndef PARSE_COERCE_H
15 #define PARSE_COERCE_H
17 #include "catalog/pg_type.h"
18 #include "parser/parse_node.h"
38 * Check for types which are in the core distribution.
39 * The built-in types can have more explicit support for type coersion, etc,
40 * since we know apriori how they should behave.
43 #define IS_BUILTIN_TYPE(t) \
46 || ((t) == BPCHAROID) \
47 || ((t) == VARCHAROID) \
49 || ((t) == BYTEAOID) \
52 || ((t) == FLOAT8OID) \
53 || ((t) == NUMERICOID) \
54 || ((t) == TIMESTAMPOID) \
55 || ((t) == INTERVALOID) \
56 || ((t) == ABSTIMEOID) \
57 || ((t) == RELTIMEOID) \
60 || ((t) == TIMETZOID) \
64 || ((t) == POINTOID) \
69 || ((t) == POLYGONOID) \
70 || ((t) == CIRCLEOID) \
74 || ((t) == VARBITOID) )
77 /* IS_BINARY_COMPATIBLE()
78 * Check for types with the same underlying binary representation.
79 * This allows us to cheat and directly exchange values without
80 * going through the trouble of calling a conversion function.
82 * Remove equivalencing of FLOAT8 and TIMESTAMP. They really are not
83 * close enough in behavior, with the TIMESTAMP reserved values
84 * and special formatting. - thomas 1999-01-24
86 #define IS_BINARY_COMPATIBLE(a,b) \
87 (((a) == BPCHAROID && (b) == TEXTOID) \
88 || ((a) == BPCHAROID && (b) == VARCHAROID) \
89 || ((a) == BPCHAROID && (b) == BYTEAOID) \
90 || ((a) == VARCHAROID && (b) == TEXTOID) \
91 || ((a) == VARCHAROID && (b) == BPCHAROID) \
92 || ((a) == VARCHAROID && (b) == BYTEAOID) \
93 || ((a) == TEXTOID && (b) == BPCHAROID) \
94 || ((a) == TEXTOID && (b) == VARCHAROID) \
95 || ((a) == TEXTOID && (b) == BYTEAOID) \
96 || ((a) == BYTEAOID && (b) == BPCHAROID) \
97 || ((a) == BYTEAOID && (b) == VARCHAROID) \
98 || ((a) == BYTEAOID && (b) == TEXTOID) \
99 || ((a) == OIDOID && (b) == INT4OID) \
100 || ((a) == OIDOID && (b) == REGPROCOID) \
101 || ((a) == INT4OID && (b) == OIDOID) \
102 || ((a) == INT4OID && (b) == REGPROCOID) \
103 || ((a) == REGPROCOID && (b) == OIDOID) \
104 || ((a) == REGPROCOID && (b) == INT4OID) \
105 || ((a) == ABSTIMEOID && (b) == INT4OID) \
106 || ((a) == INT4OID && (b) == ABSTIMEOID) \
107 || ((a) == RELTIMEOID && (b) == INT4OID) \
108 || ((a) == INT4OID && (b) == RELTIMEOID) \
109 || ((a) == INETOID && (b) == CIDROID) \
110 || ((a) == CIDROID && (b) == INETOID) \
111 || ((a) == BITOID && (b) == VARBITOID) \
112 || ((a) == VARBITOID && (b) == BITOID))
115 * These types are the most general in each of the type categories.
117 #define IS_HIGHER_TYPE(t) \
119 || ((t) == FLOAT8OID) \
120 || ((t) == INTERVALOID) \
121 || ((t) == TIMESTAMPOID) \
122 || ((t) == POLYGONOID) \
123 || ((t) == INETOID) )
126 * These types are the most general in each of the type categories.
127 * Since interval and timestamp overload so many functions, let's
128 * give timestamp the preference.
129 * Since text is a generic string type let's leave it out too.
131 #define IS_HIGHEST_TYPE(t) \
132 (((t) == FLOAT8OID) \
133 || ((t) == TIMESTAMPOID) \
134 || ((t) == INTERVALOID))
137 extern bool IsPreferredType(CATEGORY category, Oid type);
138 extern CATEGORY TypeCategory(Oid type);
140 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
141 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
142 Oid targetTypeId, int32 atttypmod);
143 extern Node *coerce_type_typmod(ParseState *pstate, Node *node,
144 Oid targetTypeId, int32 atttypmod);
146 extern bool coerce_to_boolean(ParseState *pstate, Node **pnode);
148 extern Oid select_common_type(List *typeids, const char *context);
149 extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
151 const char *context);
153 #endif /* PARSE_COERCE_H */