]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
Add:
[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.17 2000/01/26 05:58:27 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) == INT4OID) \
49                 || ((t) == INT8OID) \
50                 || ((t) == FLOAT8OID) \
51                 || ((t) == DATETIMEOID) \
52                 || ((t) == TIMESTAMPOID) \
53                 || ((t) == ABSTIMEOID) \
54                 || ((t) == RELTIMEOID) \
55                 || ((t) == CHAROID) \
56                 || ((t) == NAMEOID) \
57                 || ((t) == CASHOID) \
58                 || ((t) == POINTOID) \
59                 || ((t) == LSEGOID) \
60                 || ((t) == LINEOID) \
61                 || ((t) == BOXOID) \
62                 || ((t) == PATHOID) \
63                 || ((t) == POLYGONOID) \
64                 || ((t) == CIRCLEOID) \
65                 || ((t) == INETOID) \
66                 || ((t) == CIDROID) )
67
68
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
76  */
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))
100
101 /* IS_HIGHER_TYPE()
102  * These types are the most general in each of the type categories.
103  */
104 #define IS_HIGHER_TYPE(t) \
105                   (((t) == TEXTOID) \
106                 || ((t) == FLOAT8OID) \
107                 || ((t) == TIMESPANOID) \
108                 || ((t) == DATETIMEOID) \
109                 || ((t) == POLYGONOID) \
110                 || ((t) == INETOID) )
111
112 /* IS_HIGHEST_TYPE()
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.
117  */
118 #define IS_HIGHEST_TYPE(t) \
119                   (((t) == FLOAT8OID) \
120                 || ((t) == DATETIMEOID) \
121                 || ((t) == TIMESPANOID))
122
123
124 extern bool IsPreferredType(CATEGORY category, Oid type);
125 extern CATEGORY TypeCategory(Oid type);
126
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);
132
133 #endif   /* PARSE_COERCE_H */