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.24 2000/10/05 19:11:38 tgl 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) \
50 || ((t) == FLOAT8OID) \
51 || ((t) == NUMERICOID) \
52 || ((t) == TIMESTAMPOID) \
53 || ((t) == INTERVALOID) \
54 || ((t) == ABSTIMEOID) \
55 || ((t) == RELTIMEOID) \
58 || ((t) == TIMETZOID) \
62 || ((t) == POINTOID) \
67 || ((t) == POLYGONOID) \
68 || ((t) == CIRCLEOID) \
71 || ((t) == ZPBITOID) \
72 || ((t) == VARBITOID) )
75 /* IS_BINARY_COMPATIBLE()
76 * Check for types with the same underlying binary representation.
77 * This allows us to cheat and directly exchange values without
78 * going through the trouble of calling a conversion function.
80 * Remove equivalencing of FLOAT8 and TIMESTAMP. They really are not
81 * close enough in behavior, with the TIMESTAMP reserved values
82 * and special formatting. - thomas 1999-01-24
84 #define IS_BINARY_COMPATIBLE(a,b) \
85 (((a) == BPCHAROID && (b) == TEXTOID) \
86 || ((a) == BPCHAROID && (b) == VARCHAROID) \
87 || ((a) == VARCHAROID && (b) == TEXTOID) \
88 || ((a) == VARCHAROID && (b) == BPCHAROID) \
89 || ((a) == TEXTOID && (b) == BPCHAROID) \
90 || ((a) == TEXTOID && (b) == VARCHAROID) \
91 || ((a) == OIDOID && (b) == INT4OID) \
92 || ((a) == OIDOID && (b) == REGPROCOID) \
93 || ((a) == INT4OID && (b) == OIDOID) \
94 || ((a) == INT4OID && (b) == REGPROCOID) \
95 || ((a) == REGPROCOID && (b) == OIDOID) \
96 || ((a) == REGPROCOID && (b) == INT4OID) \
97 || ((a) == ABSTIMEOID && (b) == INT4OID) \
98 || ((a) == INT4OID && (b) == ABSTIMEOID) \
99 || ((a) == RELTIMEOID && (b) == INT4OID) \
100 || ((a) == INT4OID && (b) == RELTIMEOID) \
101 || ((a) == INETOID && (b) == CIDROID) \
102 || ((a) == CIDROID && (b) == INETOID) \
103 || ((a) == ZPBITOID && (b) == VARBITOID) \
104 || ((a) == VARBITOID && (b) == ZPBITOID))
107 * These types are the most general in each of the type categories.
109 #define IS_HIGHER_TYPE(t) \
111 || ((t) == FLOAT8OID) \
112 || ((t) == INTERVALOID) \
113 || ((t) == TIMESTAMPOID) \
114 || ((t) == POLYGONOID) \
115 || ((t) == INETOID) )
118 * These types are the most general in each of the type categories.
119 * Since interval and timestamp overload so many functions, let's
120 * give timestamp the preference.
121 * Since text is a generic string type let's leave it out too.
123 #define IS_HIGHEST_TYPE(t) \
124 (((t) == FLOAT8OID) \
125 || ((t) == TIMESTAMPOID) \
126 || ((t) == INTERVALOID))
129 extern bool IsPreferredType(CATEGORY category, Oid type);
130 extern CATEGORY TypeCategory(Oid type);
132 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
133 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
134 Oid targetTypeId, int32 atttypmod);
135 extern Node *coerce_type_typmod(ParseState *pstate, Node *node,
136 Oid targetTypeId, int32 atttypmod);
138 extern Oid select_common_type(List *typeids, const char *context);
139 extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
141 const char *context);
143 #endif /* PARSE_COERCE_H */