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