]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
OK, folks, here is the pgindent output.
[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.5 1998/09/01 04:37:32 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         USER_TYPE,
27         MIXED_TYPE
28 }                       CATEGORY;
29
30
31 /* IS_BUILTIN_TYPE()
32  * Check for types which are in the core distribution.
33  * The built-in types can have more explicit support for type coersion, etc,
34  *      since we know apriori how they should behave.
35  * - thomas 1998-05-13
36  */
37 #define IS_BUILTIN_TYPE(t) \
38                   (((t) == OIDOID) \
39                 || ((t) == BOOLOID) \
40                 || ((t) == BPCHAROID) \
41                 || ((t) == VARCHAROID) \
42                 || ((t) == TEXTOID) \
43                 || ((t) == INT4OID) \
44                 || ((t) == INT8OID) \
45                 || ((t) == FLOAT8OID) \
46                 || ((t) == DATETIMEOID) \
47                 || ((t) == TIMESTAMPOID) \
48                 || ((t) == ABSTIMEOID) \
49                 || ((t) == RELTIMEOID) \
50                 || ((t) == CHAROID) \
51                 || ((t) == NAMEOID) \
52                 || ((t) == CASHOID) \
53                 || ((t) == POINTOID) \
54                 || ((t) == LSEGOID) \
55                 || ((t) == LINEOID) \
56                 || ((t) == BOXOID) \
57                 || ((t) == PATHOID) \
58                 || ((t) == POLYGONOID) \
59                 || ((t) == CIRCLEOID))
60
61
62 /* IS_BINARY_COMPATIBLE()
63  * Check for types with the same underlying binary representation.
64  * This allows us to cheat and directly exchange values without
65  *      going through the trouble of calling a conversion function.
66  */
67 #define IS_BINARY_COMPATIBLE(a,b) \
68                   (((a) == BPCHAROID && (b) == TEXTOID) \
69                 || ((a) == BPCHAROID && (b) == VARCHAROID) \
70                 || ((a) == VARCHAROID && (b) == TEXTOID) \
71                 || ((a) == VARCHAROID && (b) == BPCHAROID) \
72                 || ((a) == TEXTOID && (b) == BPCHAROID) \
73                 || ((a) == TEXTOID && (b) == VARCHAROID) \
74                 || ((a) == OIDOID && (b) == INT4OID) \
75                 || ((a) == INT4OID && (b) == TIMESTAMPOID) \
76                 || ((a) == DATETIMEOID && (b) == FLOAT8OID) \
77                 || ((a) == FLOAT8OID && (b) == DATETIMEOID) \
78                 || ((a) == ABSTIMEOID && (b) == TIMESTAMPOID) \
79                 || ((a) == ABSTIMEOID && (b) == INT4OID) \
80                 || ((a) == TIMESTAMPOID && (b) == ABSTIMEOID) \
81                 || ((a) == TIMESTAMPOID && (b) == INT4OID) \
82                 || ((a) == INT4OID && (b) == OIDOID) \
83                 || ((a) == INT4OID && (b) == ABSTIMEOID) \
84                 || ((a) == INT4OID && (b) == TIMESTAMPOID) \
85                 || ((a) == RELTIMEOID && (b) == INT4OID) \
86                 || ((a) == INT4OID && (b) == RELTIMEOID))
87
88 /* IS_HIGHER_TYPE()
89  * These types are the most general in each of the type categories.
90  */
91 #define IS_HIGHER_TYPE(t) \
92                   (((t) == TEXTOID) \
93                 || ((t) == FLOAT8OID) \
94                 || ((t) == TIMESPANOID) \
95                 || ((t) == DATETIMEOID) \
96                 || ((t) == POLYGONOID))
97
98 /* IS_HIGHEST_TYPE()
99  * These types are the most general in each of the type categories.
100  * Since timespan and datetime overload so many functions, let's
101  *      give datetime the preference.
102  * Since text is a generic string type let's leave it out too.
103  */
104 #define IS_HIGHEST_TYPE(t) \
105                   (((t) == FLOAT8OID) \
106                 || ((t) == DATETIMEOID) \
107                 || ((t) == TIMESPANOID))
108
109
110 extern bool IsPreferredType(CATEGORY category, Oid type);
111 extern Oid      PreferredType(CATEGORY category, Oid type);
112 extern CATEGORY TypeCategory(Oid type);
113
114 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
115 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId);
116
117 #endif   /* PARSE_COERCE_H */