]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
Add separate type category for bit string types, allowing mixed bit/varbit
[postgresql] / src / include / parser / parse_coerce.h
1 /*-------------------------------------------------------------------------
2  *
3  * parse_coerce.h
4  *
5  *      Routines for type coercion.
6  *
7  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: parse_coerce.h,v 1.25 2000/11/17 19:57:48 petere Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PARSE_COERCE_H
15 #define PARSE_COERCE_H
16
17 #include "catalog/pg_type.h"
18 #include "parser/parse_node.h"
19
20 typedef enum CATEGORY
21 {
22         INVALID_TYPE,
23         UNKNOWN_TYPE,
24         BOOLEAN_TYPE,
25         STRING_TYPE,
26         BITSTRING_TYPE,
27         NUMERIC_TYPE,
28         DATETIME_TYPE,
29         TIMESPAN_TYPE,
30         GEOMETRIC_TYPE,
31         NETWORK_TYPE,
32         USER_TYPE,
33         MIXED_TYPE
34 } CATEGORY;
35
36
37 /* IS_BUILTIN_TYPE()
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.
41  * - thomas 1998-05-13
42  */
43 #define IS_BUILTIN_TYPE(t) \
44                   (((t) == OIDOID) \
45                 || ((t) == BOOLOID) \
46                 || ((t) == BPCHAROID) \
47                 || ((t) == VARCHAROID) \
48                 || ((t) == TEXTOID) \
49                 || ((t) == INT4OID) \
50                 || ((t) == INT8OID) \
51                 || ((t) == FLOAT8OID) \
52                 || ((t) == NUMERICOID) \
53                 || ((t) == TIMESTAMPOID) \
54                 || ((t) == INTERVALOID) \
55                 || ((t) == ABSTIMEOID) \
56                 || ((t) == RELTIMEOID) \
57                 || ((t) == DATEOID) \
58                 || ((t) == TIMEOID) \
59                 || ((t) == TIMETZOID) \
60                 || ((t) == CHAROID) \
61                 || ((t) == NAMEOID) \
62                 || ((t) == CASHOID) \
63                 || ((t) == POINTOID) \
64                 || ((t) == LSEGOID) \
65                 || ((t) == LINEOID) \
66                 || ((t) == BOXOID) \
67                 || ((t) == PATHOID) \
68                 || ((t) == POLYGONOID) \
69                 || ((t) == CIRCLEOID) \
70                 || ((t) == INETOID) \
71                 || ((t) == CIDROID) \
72                 || ((t) == ZPBITOID) \
73                 || ((t) == VARBITOID) )
74
75
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.
80  *
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
84  */
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))
106
107 /* IS_HIGHER_TYPE()
108  * These types are the most general in each of the type categories.
109  */
110 #define IS_HIGHER_TYPE(t) \
111                   (((t) == TEXTOID) \
112                 || ((t) == FLOAT8OID) \
113                 || ((t) == INTERVALOID) \
114                 || ((t) == TIMESTAMPOID) \
115                 || ((t) == POLYGONOID) \
116                 || ((t) == INETOID) )
117
118 /* IS_HIGHEST_TYPE()
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.
123  */
124 #define IS_HIGHEST_TYPE(t) \
125                   (((t) == FLOAT8OID) \
126                 || ((t) == TIMESTAMPOID) \
127                 || ((t) == INTERVALOID))
128
129
130 extern bool IsPreferredType(CATEGORY category, Oid type);
131 extern CATEGORY TypeCategory(Oid type);
132
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);
138
139 extern Oid select_common_type(List *typeids, const char *context);
140 extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
141                                                                    Oid targetTypeId,
142                                                                    const char *context);
143
144 #endif   /* PARSE_COERCE_H */