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.17 2000/01/26 05:58:27 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) \
50 || ((t) == FLOAT8OID) \
51 || ((t) == DATETIMEOID) \
52 || ((t) == TIMESTAMPOID) \
53 || ((t) == ABSTIMEOID) \
54 || ((t) == RELTIMEOID) \
58 || ((t) == POINTOID) \
63 || ((t) == POLYGONOID) \
64 || ((t) == CIRCLEOID) \
69 /* IS_BINARY_COMPATIBLE()
70 * Check for types with the same underlying binary representation.
71 * This allows us to cheat and directly exchange values without
72 * going through the trouble of calling a conversion function.
73 * Remove equivalencing of FLOAT8 and DATETIME. They really are not
74 * close enough in behavior, with the DATETIME reserved values
75 * and special formatting. - thomas 1999-01-24
77 #define IS_BINARY_COMPATIBLE(a,b) \
78 (((a) == BPCHAROID && (b) == TEXTOID) \
79 || ((a) == BPCHAROID && (b) == VARCHAROID) \
80 || ((a) == VARCHAROID && (b) == TEXTOID) \
81 || ((a) == VARCHAROID && (b) == BPCHAROID) \
82 || ((a) == TEXTOID && (b) == BPCHAROID) \
83 || ((a) == TEXTOID && (b) == VARCHAROID) \
84 || ((a) == OIDOID && (b) == INT4OID) \
85 || ((a) == OIDOID && (b) == REGPROCOID) \
86 || ((a) == INT4OID && (b) == OIDOID) \
87 || ((a) == INT4OID && (b) == REGPROCOID) \
88 || ((a) == REGPROCOID && (b) == OIDOID) \
89 || ((a) == REGPROCOID && (b) == INT4OID) \
90 || ((a) == ABSTIMEOID && (b) == TIMESTAMPOID) \
91 || ((a) == ABSTIMEOID && (b) == INT4OID) \
92 || ((a) == TIMESTAMPOID && (b) == ABSTIMEOID) \
93 || ((a) == TIMESTAMPOID && (b) == INT4OID) \
94 || ((a) == INT4OID && (b) == ABSTIMEOID) \
95 || ((a) == INT4OID && (b) == TIMESTAMPOID) \
96 || ((a) == RELTIMEOID && (b) == INT4OID) \
97 || ((a) == INT4OID && (b) == RELTIMEOID) \
98 || ((a) == INETOID && (b) == CIDROID) \
99 || ((a) == CIDROID && (b) == INETOID))
102 * These types are the most general in each of the type categories.
104 #define IS_HIGHER_TYPE(t) \
106 || ((t) == FLOAT8OID) \
107 || ((t) == TIMESPANOID) \
108 || ((t) == DATETIMEOID) \
109 || ((t) == POLYGONOID) \
110 || ((t) == INETOID) )
113 * These types are the most general in each of the type categories.
114 * Since timespan and datetime overload so many functions, let's
115 * give datetime the preference.
116 * Since text is a generic string type let's leave it out too.
118 #define IS_HIGHEST_TYPE(t) \
119 (((t) == FLOAT8OID) \
120 || ((t) == DATETIMEOID) \
121 || ((t) == TIMESPANOID))
124 extern bool IsPreferredType(CATEGORY category, Oid type);
125 extern CATEGORY TypeCategory(Oid type);
127 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
128 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
129 Oid targetTypeId, int32 atttypmod);
130 extern Node *coerce_type_typmod(ParseState *pstate, Node *node,
131 Oid targetTypeId, int32 atttypmod);
133 #endif /* PARSE_COERCE_H */