1 /*-------------------------------------------------------------------------
5 * Routines for type coercion.
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: parse_coerce.h,v 1.25 2000/11/17 19:57:48 petere 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) \
51 || ((t) == FLOAT8OID) \
52 || ((t) == NUMERICOID) \
53 || ((t) == TIMESTAMPOID) \
54 || ((t) == INTERVALOID) \
55 || ((t) == ABSTIMEOID) \
56 || ((t) == RELTIMEOID) \
59 || ((t) == TIMETZOID) \
63 || ((t) == POINTOID) \
68 || ((t) == POLYGONOID) \
69 || ((t) == CIRCLEOID) \
72 || ((t) == ZPBITOID) \
73 || ((t) == VARBITOID) )
76 /* IS_BINARY_COMPATIBLE()
77 * Check for types with the same underlying binary representation.
78 * This allows us to cheat and directly exchange values without
79 * going through the trouble of calling a conversion function.
81 * Remove equivalencing of FLOAT8 and TIMESTAMP. They really are not
82 * close enough in behavior, with the TIMESTAMP reserved values
83 * and special formatting. - thomas 1999-01-24
85 #define IS_BINARY_COMPATIBLE(a,b) \
86 (((a) == BPCHAROID && (b) == TEXTOID) \
87 || ((a) == BPCHAROID && (b) == VARCHAROID) \
88 || ((a) == VARCHAROID && (b) == TEXTOID) \
89 || ((a) == VARCHAROID && (b) == BPCHAROID) \
90 || ((a) == TEXTOID && (b) == BPCHAROID) \
91 || ((a) == TEXTOID && (b) == VARCHAROID) \
92 || ((a) == OIDOID && (b) == INT4OID) \
93 || ((a) == OIDOID && (b) == REGPROCOID) \
94 || ((a) == INT4OID && (b) == OIDOID) \
95 || ((a) == INT4OID && (b) == REGPROCOID) \
96 || ((a) == REGPROCOID && (b) == OIDOID) \
97 || ((a) == REGPROCOID && (b) == INT4OID) \
98 || ((a) == ABSTIMEOID && (b) == INT4OID) \
99 || ((a) == INT4OID && (b) == ABSTIMEOID) \
100 || ((a) == RELTIMEOID && (b) == INT4OID) \
101 || ((a) == INT4OID && (b) == RELTIMEOID) \
102 || ((a) == INETOID && (b) == CIDROID) \
103 || ((a) == CIDROID && (b) == INETOID) \
104 || ((a) == ZPBITOID && (b) == VARBITOID) \
105 || ((a) == VARBITOID && (b) == ZPBITOID))
108 * These types are the most general in each of the type categories.
110 #define IS_HIGHER_TYPE(t) \
112 || ((t) == FLOAT8OID) \
113 || ((t) == INTERVALOID) \
114 || ((t) == TIMESTAMPOID) \
115 || ((t) == POLYGONOID) \
116 || ((t) == INETOID) )
119 * These types are the most general in each of the type categories.
120 * Since interval and timestamp overload so many functions, let's
121 * give timestamp the preference.
122 * Since text is a generic string type let's leave it out too.
124 #define IS_HIGHEST_TYPE(t) \
125 (((t) == FLOAT8OID) \
126 || ((t) == TIMESTAMPOID) \
127 || ((t) == INTERVALOID))
130 extern bool IsPreferredType(CATEGORY category, Oid type);
131 extern CATEGORY TypeCategory(Oid type);
133 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
134 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
135 Oid targetTypeId, int32 atttypmod);
136 extern Node *coerce_type_typmod(ParseState *pstate, Node *node,
137 Oid targetTypeId, int32 atttypmod);
139 extern Oid select_common_type(List *typeids, const char *context);
140 extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
142 const char *context);
144 #endif /* PARSE_COERCE_H */