]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
0549386a397a76c8ba1655cd88424de210e8f2b8
[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.20 2000/03/20 04:02:47 momjian 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         NUMERIC_TYPE,
27         DATETIME_TYPE,
28         TIMESPAN_TYPE,
29         GEOMETRIC_TYPE,
30         NETWORK_TYPE,
31         USER_TYPE,
32         MIXED_TYPE
33 } CATEGORY;
34
35
36 /* IS_BUILTIN_TYPE()
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.
40  * - thomas 1998-05-13
41  */
42 #define IS_BUILTIN_TYPE(t) \
43                   (((t) == OIDOID) \
44                 || ((t) == BOOLOID) \
45                 || ((t) == BPCHAROID) \
46                 || ((t) == VARCHAROID) \
47                 || ((t) == TEXTOID) \
48                 || ((t) == BYTEAOID) \
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
73
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
81  */
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))
107
108 /* IS_HIGHER_TYPE()
109  * These types are the most general in each of the type categories.
110  */
111 #define IS_HIGHER_TYPE(t) \
112                   (((t) == TEXTOID) \
113                 || ((t) == FLOAT8OID) \
114                 || ((t) == INTERVALOID) \
115                 || ((t) == TIMESTAMPOID) \
116                 || ((t) == POLYGONOID) \
117                 || ((t) == INETOID) )
118
119 /* IS_HIGHEST_TYPE()
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.
124  */
125 #define IS_HIGHEST_TYPE(t) \
126                   (((t) == FLOAT8OID) \
127                 || ((t) == TIMESTAMPOID) \
128                 || ((t) == INTERVALOID))
129
130
131 extern bool IsPreferredType(CATEGORY category, Oid type);
132 extern CATEGORY TypeCategory(Oid type);
133
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);
139
140 #endif   /* PARSE_COERCE_H */