1 /*-------------------------------------------------------------------------
7 * Copyright (c) 1994, Regents of the University of California
9 * $Id: parse_coerce.h,v 1.13 1999/07/14 01:20:25 momjian Exp $
11 *-------------------------------------------------------------------------
13 #ifndef PARSE_COERCE_H
14 #define PARSE_COERCE_H
16 #include "nodes/pg_list.h"
17 #include "parser/parse_node.h"
36 * Check for types which are in the core distribution.
37 * The built-in types can have more explicit support for type coersion, etc,
38 * since we know apriori how they should behave.
41 #define IS_BUILTIN_TYPE(t) \
44 || ((t) == BPCHAROID) \
45 || ((t) == VARCHAROID) \
49 || ((t) == FLOAT8OID) \
50 || ((t) == DATETIMEOID) \
51 || ((t) == TIMESTAMPOID) \
52 || ((t) == ABSTIMEOID) \
53 || ((t) == RELTIMEOID) \
57 || ((t) == POINTOID) \
62 || ((t) == POLYGONOID) \
63 || ((t) == CIRCLEOID) \
68 /* IS_BINARY_COMPATIBLE()
69 * Check for types with the same underlying binary representation.
70 * This allows us to cheat and directly exchange values without
71 * going through the trouble of calling a conversion function.
72 * Remove equivalencing of FLOAT8 and DATETIME. They really are not
73 * close enough in behavior, with the DATETIME reserved values
74 * and special formatting. - thomas 1999-01-24
76 #define IS_BINARY_COMPATIBLE(a,b) \
77 (((a) == BPCHAROID && (b) == TEXTOID) \
78 || ((a) == BPCHAROID && (b) == VARCHAROID) \
79 || ((a) == VARCHAROID && (b) == TEXTOID) \
80 || ((a) == VARCHAROID && (b) == BPCHAROID) \
81 || ((a) == TEXTOID && (b) == BPCHAROID) \
82 || ((a) == TEXTOID && (b) == VARCHAROID) \
83 || ((a) == OIDOID && (b) == INT4OID) \
84 || ((a) == OIDOID && (b) == REGPROCOID) \
85 || ((a) == INT4OID && (b) == OIDOID) \
86 || ((a) == INT4OID && (b) == REGPROCOID) \
87 || ((a) == REGPROCOID && (b) == OIDOID) \
88 || ((a) == REGPROCOID && (b) == INT4OID) \
89 || ((a) == ABSTIMEOID && (b) == TIMESTAMPOID) \
90 || ((a) == ABSTIMEOID && (b) == INT4OID) \
91 || ((a) == TIMESTAMPOID && (b) == ABSTIMEOID) \
92 || ((a) == TIMESTAMPOID && (b) == INT4OID) \
93 || ((a) == INT4OID && (b) == ABSTIMEOID) \
94 || ((a) == INT4OID && (b) == TIMESTAMPOID) \
95 || ((a) == RELTIMEOID && (b) == INT4OID) \
96 || ((a) == INT4OID && (b) == RELTIMEOID) \
97 || ((a) == INETOID && (b) == CIDROID) \
98 || ((a) == CIDROID && (b) == INETOID))
101 * These types are the most general in each of the type categories.
103 #define IS_HIGHER_TYPE(t) \
105 || ((t) == FLOAT8OID) \
106 || ((t) == TIMESPANOID) \
107 || ((t) == DATETIMEOID) \
108 || ((t) == POLYGONOID) \
109 || ((t) == INETOID) )
112 * These types are the most general in each of the type categories.
113 * Since timespan and datetime overload so many functions, let's
114 * give datetime the preference.
115 * Since text is a generic string type let's leave it out too.
117 #define IS_HIGHEST_TYPE(t) \
118 (((t) == FLOAT8OID) \
119 || ((t) == DATETIMEOID) \
120 || ((t) == TIMESPANOID))
123 extern bool IsPreferredType(CATEGORY category, Oid type);
124 extern CATEGORY TypeCategory(Oid type);
126 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
127 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
128 Oid targetTypeId, int32 atttypmod);
130 #endif /* PARSE_COERCE_H */