1 /*-------------------------------------------------------------------------
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: parse_coerce.h,v 1.2 1998/05/29 14:02:28 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) \
42 || ((t) == DATETIMEOID) \
43 || ((t) == FLOAT8OID) \
44 || ((t) == TIMESTAMPOID) \
45 || ((t) == ABSTIMEOID) \
46 || ((t) == RELTIMEOID) \
50 || ((t) == POINTOID) \
55 || ((t) == POLYGONOID) \
56 || ((t) == CIRCLEOID))
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.
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))
83 * These types are the most general in each of the type categories.
85 #define IS_HIGHER_TYPE(t) \
87 || ((t) == FLOAT8OID) \
88 || ((t) == TIMESPANOID) \
89 || ((t) == DATETIMEOID) \
90 || ((t) == POLYGONOID))
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.
98 #define IS_HIGHEST_TYPE(t) \
100 || ((t) == DATETIMEOID) \
101 || ((t) == TIMESPANOID))
104 extern bool IsPreferredType(CATEGORY category, Oid type);
105 extern Oid PreferredType(CATEGORY category, Oid type);
106 extern CATEGORY TypeCategory(Oid type);
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);
111 #endif /* PARSE_COERCE_H */