]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
Add NAMEOID as built-in 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.2 1998/05/29 14:02:28 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) == DATETIMEOID) \
43                 || ((t) == FLOAT8OID) \
44                 || ((t) == TIMESTAMPOID) \
45                 || ((t) == ABSTIMEOID) \
46                 || ((t) == RELTIMEOID) \
47                 || ((t) == CHAROID) \
48                 || ((t) == NAMEOID) \
49                 || ((t) == CASHOID) \
50                 || ((t) == POINTOID) \
51                 || ((t) == LSEGOID) \
52                 || ((t) == LINEOID) \
53                 || ((t) == BOXOID) \
54                 || ((t) == PATHOID) \
55                 || ((t) == POLYGONOID) \
56                 || ((t) == CIRCLEOID))
57
58
59 /* IS_BINARY_COMPATIBLE()
60  * Check for types with the same underlying binary representation.
61  * This allows us to cheat and directly exchange values without
62  *  going through the trouble of calling a conversion function.
63  */
64 #define IS_BINARY_COMPATIBLE(a,b) \
65                   (((a) == BPCHAROID && (b) == TEXTOID) \
66                 || ((a) == BPCHAROID && (b) == VARCHAROID) \
67                 || ((a) == VARCHAROID && (b) == TEXTOID) \
68                 || ((a) == VARCHAROID && (b) == BPCHAROID) \
69                 || ((a) == TEXTOID && (b) == BPCHAROID) \
70                 || ((a) == TEXTOID && (b) == VARCHAROID) \
71                 || ((a) == DATETIMEOID && (b) == FLOAT8OID) \
72                 || ((a) == FLOAT8OID && (b) == DATETIMEOID) \
73                 || ((a) == ABSTIMEOID && (b) == TIMESTAMPOID) \
74                 || ((a) == ABSTIMEOID && (b) == INT4OID) \
75                 || ((a) == TIMESTAMPOID && (b) == ABSTIMEOID) \
76                 || ((a) == TIMESTAMPOID && (b) == INT4OID) \
77                 || ((a) == INT4OID && (b) == ABSTIMEOID) \
78                 || ((a) == INT4OID && (b) == TIMESTAMPOID) \
79                 || ((a) == RELTIMEOID && (b) == INT4OID) \
80                 || ((a) == INT4OID && (b) == RELTIMEOID))
81
82 /* IS_HIGHER_TYPE()
83  * These types are the most general in each of the type categories.
84  */
85 #define IS_HIGHER_TYPE(t) \
86                   (((t) == TEXTOID) \
87                 || ((t) == FLOAT8OID) \
88                 || ((t) == TIMESPANOID) \
89                 || ((t) == DATETIMEOID) \
90                 || ((t) == POLYGONOID))
91
92 /* IS_HIGHEST_TYPE()
93  * These types are the most general in each of the type categories.
94  * Since timespan and datetime overload so many functions, let's
95  *  give datetime the preference.
96  * Since text is a generic string type let's leave it out too.
97  */
98 #define IS_HIGHEST_TYPE(t) \
99                   (((t) == FLOAT8OID) \
100                 || ((t) == DATETIMEOID) \
101                 || ((t) == TIMESPANOID))
102
103
104 extern bool IsPreferredType(CATEGORY category, Oid type);
105 extern Oid PreferredType(CATEGORY category, Oid type);
106 extern CATEGORY TypeCategory(Oid type);
107
108 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
109 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId);
110
111 #endif                                                  /* PARSE_COERCE_H */