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.20 2000/03/20 04:02:47 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"
37 * Check for types which are in the core distribution.
38 * The built-in types can have more explicit support for type coersion, etc,
39 * since we know apriori how they should behave.
42 #define IS_BUILTIN_TYPE(t) \
45 || ((t) == BPCHAROID) \
46 || ((t) == VARCHAROID) \
48 || ((t) == BYTEAOID) \
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) \
74 /* IS_BINARY_COMPATIBLE()
75 * Check for types with the same underlying binary representation.
76 * This allows us to cheat and directly exchange values without
77 * going through the trouble of calling a conversion function.
78 * Remove equivalencing of FLOAT8 and TIMESTAMP. They really are not
79 * close enough in behavior, with the TIMESTAMP reserved values
80 * and special formatting. - thomas 1999-01-24
82 #define IS_BINARY_COMPATIBLE(a,b) \
83 (((a) == BPCHAROID && (b) == TEXTOID) \
84 || ((a) == BPCHAROID && (b) == VARCHAROID) \
85 || ((a) == BPCHAROID && (b) == BYTEAOID) \
86 || ((a) == VARCHAROID && (b) == TEXTOID) \
87 || ((a) == VARCHAROID && (b) == BPCHAROID) \
88 || ((a) == VARCHAROID && (b) == BYTEAOID) \
89 || ((a) == TEXTOID && (b) == BPCHAROID) \
90 || ((a) == TEXTOID && (b) == VARCHAROID) \
91 || ((a) == TEXTOID && (b) == BYTEAOID) \
92 || ((a) == BYTEAOID && (b) == BPCHAROID) \
93 || ((a) == BYTEAOID && (b) == VARCHAROID) \
94 || ((a) == BYTEAOID && (b) == TEXTOID) \
95 || ((a) == OIDOID && (b) == INT4OID) \
96 || ((a) == OIDOID && (b) == REGPROCOID) \
97 || ((a) == INT4OID && (b) == OIDOID) \
98 || ((a) == INT4OID && (b) == REGPROCOID) \
99 || ((a) == REGPROCOID && (b) == OIDOID) \
100 || ((a) == REGPROCOID && (b) == INT4OID) \
101 || ((a) == ABSTIMEOID && (b) == INT4OID) \
102 || ((a) == INT4OID && (b) == ABSTIMEOID) \
103 || ((a) == RELTIMEOID && (b) == INT4OID) \
104 || ((a) == INT4OID && (b) == RELTIMEOID) \
105 || ((a) == INETOID && (b) == CIDROID) \
106 || ((a) == CIDROID && (b) == INETOID))
109 * These types are the most general in each of the type categories.
111 #define IS_HIGHER_TYPE(t) \
113 || ((t) == FLOAT8OID) \
114 || ((t) == INTERVALOID) \
115 || ((t) == TIMESTAMPOID) \
116 || ((t) == POLYGONOID) \
117 || ((t) == INETOID) )
120 * These types are the most general in each of the type categories.
121 * Since interval and timestamp overload so many functions, let's
122 * give timestamp the preference.
123 * Since text is a generic string type let's leave it out too.
125 #define IS_HIGHEST_TYPE(t) \
126 (((t) == FLOAT8OID) \
127 || ((t) == TIMESTAMPOID) \
128 || ((t) == INTERVALOID))
131 extern bool IsPreferredType(CATEGORY category, Oid type);
132 extern CATEGORY TypeCategory(Oid type);
134 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
135 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
136 Oid targetTypeId, int32 atttypmod);
137 extern Node *coerce_type_typmod(ParseState *pstate, Node *node,
138 Oid targetTypeId, int32 atttypmod);
140 #endif /* PARSE_COERCE_H */