]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
Cleanup of /include #include's, for 6.6 only.
[postgresql] / src / include / parser / parse_coerce.h
1 /*-------------------------------------------------------------------------
2  *
3  * parse_coerce.h
4  *
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: parse_coerce.h,v 1.13 1999/07/14 01:20:25 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef PARSE_COERCE_H
14 #define PARSE_COERCE_H
15
16 #include "nodes/pg_list.h"
17 #include "parser/parse_node.h"
18
19 typedef enum CATEGORY
20 {
21         INVALID_TYPE,
22         UNKNOWN_TYPE,
23         BOOLEAN_TYPE,
24         STRING_TYPE,
25         NUMERIC_TYPE,
26         DATETIME_TYPE,
27         TIMESPAN_TYPE,
28         GEOMETRIC_TYPE,
29         NETWORK_TYPE,
30         USER_TYPE,
31         MIXED_TYPE
32 } CATEGORY;
33
34
35 /* IS_BUILTIN_TYPE()
36  * Check for types which are in the core distribution.
37  * The built-in types can have more explicit support for type coersion, etc,
38  *      since we know apriori how they should behave.
39  * - thomas 1998-05-13
40  */
41 #define IS_BUILTIN_TYPE(t) \
42                   (((t) == OIDOID) \
43                 || ((t) == BOOLOID) \
44                 || ((t) == BPCHAROID) \
45                 || ((t) == VARCHAROID) \
46                 || ((t) == TEXTOID) \
47                 || ((t) == INT4OID) \
48                 || ((t) == INT8OID) \
49                 || ((t) == FLOAT8OID) \
50                 || ((t) == DATETIMEOID) \
51                 || ((t) == TIMESTAMPOID) \
52                 || ((t) == ABSTIMEOID) \
53                 || ((t) == RELTIMEOID) \
54                 || ((t) == CHAROID) \
55                 || ((t) == NAMEOID) \
56                 || ((t) == CASHOID) \
57                 || ((t) == POINTOID) \
58                 || ((t) == LSEGOID) \
59                 || ((t) == LINEOID) \
60                 || ((t) == BOXOID) \
61                 || ((t) == PATHOID) \
62                 || ((t) == POLYGONOID) \
63                 || ((t) == CIRCLEOID) \
64                 || ((t) == INETOID) \
65                 || ((t) == CIDROID) )
66
67
68 /* IS_BINARY_COMPATIBLE()
69  * Check for types with the same underlying binary representation.
70  * This allows us to cheat and directly exchange values without
71  *      going through the trouble of calling a conversion function.
72  * Remove equivalencing of FLOAT8 and DATETIME. They really are not
73  *      close enough in behavior, with the DATETIME reserved values
74  *      and special formatting. - thomas 1999-01-24
75  */
76 #define IS_BINARY_COMPATIBLE(a,b) \
77                   (((a) == BPCHAROID && (b) == TEXTOID) \
78                 || ((a) == BPCHAROID && (b) == VARCHAROID) \
79                 || ((a) == VARCHAROID && (b) == TEXTOID) \
80                 || ((a) == VARCHAROID && (b) == BPCHAROID) \
81                 || ((a) == TEXTOID && (b) == BPCHAROID) \
82                 || ((a) == TEXTOID && (b) == VARCHAROID) \
83                 || ((a) == OIDOID && (b) == INT4OID) \
84                 || ((a) == OIDOID && (b) == REGPROCOID) \
85                 || ((a) == INT4OID && (b) == OIDOID) \
86                 || ((a) == INT4OID && (b) == REGPROCOID) \
87                 || ((a) == REGPROCOID && (b) == OIDOID) \
88                 || ((a) == REGPROCOID && (b) == INT4OID) \
89                 || ((a) == ABSTIMEOID && (b) == TIMESTAMPOID) \
90                 || ((a) == ABSTIMEOID && (b) == INT4OID) \
91                 || ((a) == TIMESTAMPOID && (b) == ABSTIMEOID) \
92                 || ((a) == TIMESTAMPOID && (b) == INT4OID) \
93                 || ((a) == INT4OID && (b) == ABSTIMEOID) \
94                 || ((a) == INT4OID && (b) == TIMESTAMPOID) \
95                 || ((a) == RELTIMEOID && (b) == INT4OID) \
96                 || ((a) == INT4OID && (b) == RELTIMEOID) \
97                 || ((a) == INETOID && (b) == CIDROID) \
98                 || ((a) == CIDROID && (b) == INETOID))
99
100 /* IS_HIGHER_TYPE()
101  * These types are the most general in each of the type categories.
102  */
103 #define IS_HIGHER_TYPE(t) \
104                   (((t) == TEXTOID) \
105                 || ((t) == FLOAT8OID) \
106                 || ((t) == TIMESPANOID) \
107                 || ((t) == DATETIMEOID) \
108                 || ((t) == POLYGONOID) \
109                 || ((t) == INETOID) )
110
111 /* IS_HIGHEST_TYPE()
112  * These types are the most general in each of the type categories.
113  * Since timespan and datetime overload so many functions, let's
114  *      give datetime the preference.
115  * Since text is a generic string type let's leave it out too.
116  */
117 #define IS_HIGHEST_TYPE(t) \
118                   (((t) == FLOAT8OID) \
119                 || ((t) == DATETIMEOID) \
120                 || ((t) == TIMESPANOID))
121
122
123 extern bool IsPreferredType(CATEGORY category, Oid type);
124 extern CATEGORY TypeCategory(Oid type);
125
126 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
127 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
128                         Oid targetTypeId, int32 atttypmod);
129
130 #endif   /* PARSE_COERCE_H */