1 /*-------------------------------------------------------------------------
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: parse_coerce.h,v 1.3 1998/07/08 14:18:45 thomas Exp $
11 *-------------------------------------------------------------------------
13 #ifndef PARSE_COERCE_H
14 #define PARSE_COERCE_H
16 typedef enum CATEGORY {
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.
36 #define IS_BUILTIN_TYPE(t) \
38 || ((t) == BPCHAROID) \
39 || ((t) == VARCHAROID) \
43 || ((t) == FLOAT8OID) \
44 || ((t) == DATETIMEOID) \
45 || ((t) == TIMESTAMPOID) \
46 || ((t) == ABSTIMEOID) \
47 || ((t) == RELTIMEOID) \
51 || ((t) == POINTOID) \
56 || ((t) == POLYGONOID) \
57 || ((t) == CIRCLEOID))
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.
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))
84 * These types are the most general in each of the type categories.
86 #define IS_HIGHER_TYPE(t) \
88 || ((t) == FLOAT8OID) \
89 || ((t) == TIMESPANOID) \
90 || ((t) == DATETIMEOID) \
91 || ((t) == POLYGONOID))
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.
99 #define IS_HIGHEST_TYPE(t) \
100 (((t) == FLOAT8OID) \
101 || ((t) == DATETIMEOID) \
102 || ((t) == TIMESPANOID))
105 extern bool IsPreferredType(CATEGORY category, Oid type);
106 extern Oid PreferredType(CATEGORY category, Oid type);
107 extern CATEGORY TypeCategory(Oid type);
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);
112 #endif /* PARSE_COERCE_H */