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