]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
Another pgindent run. Fixes enum indenting, and improves #endif
[postgresql] / src / include / parser / parse_coerce.h
1 /*-------------------------------------------------------------------------
2  *
3  * parse_coerce.h
4  *
5  *      Routines for type coercion.
6  *
7  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: parse_coerce.h,v 1.36 2001/10/28 06:26:08 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PARSE_COERCE_H
15 #define PARSE_COERCE_H
16
17 #include "catalog/pg_type.h"
18 #include "parser/parse_node.h"
19
20 typedef enum CATEGORY
21 {
22         INVALID_TYPE,
23         UNKNOWN_TYPE,
24         BOOLEAN_TYPE,
25         STRING_TYPE,
26         BITSTRING_TYPE,
27         NUMERIC_TYPE,
28         DATETIME_TYPE,
29         TIMESPAN_TYPE,
30         GEOMETRIC_TYPE,
31         NETWORK_TYPE,
32         USER_TYPE,
33         MIXED_TYPE
34 } CATEGORY;
35
36
37 /* IS_BINARY_COMPATIBLE()
38  * Check for types with the same underlying binary representation.
39  * This allows us to cheat and directly exchange values without
40  *      going through the trouble of calling a conversion function.
41  *
42  * Remove equivalencing of FLOAT8 and TIMESTAMP. They really are not
43  *      close enough in behavior, with the TIMESTAMP reserved values
44  *      and special formatting. - thomas 1999-01-24
45  */
46 #define IS_BINARY_COMPATIBLE(a,b) \
47                   (((a) == BPCHAROID && (b) == TEXTOID) \
48                 || ((a) == BPCHAROID && (b) == VARCHAROID) \
49                 || ((a) == VARCHAROID && (b) == TEXTOID) \
50                 || ((a) == VARCHAROID && (b) == BPCHAROID) \
51                 || ((a) == TEXTOID && (b) == BPCHAROID) \
52                 || ((a) == TEXTOID && (b) == VARCHAROID) \
53                 || ((a) == OIDOID && (b) == INT4OID) \
54                 || ((a) == OIDOID && (b) == REGPROCOID) \
55                 || ((a) == INT4OID && (b) == OIDOID) \
56                 || ((a) == INT4OID && (b) == REGPROCOID) \
57                 || ((a) == REGPROCOID && (b) == OIDOID) \
58                 || ((a) == REGPROCOID && (b) == INT4OID) \
59                 || ((a) == ABSTIMEOID && (b) == INT4OID) \
60                 || ((a) == INT4OID && (b) == ABSTIMEOID) \
61                 || ((a) == RELTIMEOID && (b) == INT4OID) \
62                 || ((a) == INT4OID && (b) == RELTIMEOID) \
63                 || ((a) == INETOID && (b) == CIDROID) \
64                 || ((a) == CIDROID && (b) == INETOID) \
65                 || ((a) == BITOID && (b) == VARBITOID) \
66                 || ((a) == VARBITOID && (b) == BITOID))
67
68
69 extern bool IsPreferredType(CATEGORY category, Oid type);
70 extern CATEGORY TypeCategory(Oid type);
71
72 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids);
73 extern Node *coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
74                         Oid targetTypeId, int32 atttypmod);
75 extern Node *coerce_type_typmod(ParseState *pstate, Node *node,
76                                    Oid targetTypeId, int32 atttypmod);
77
78 extern bool coerce_to_boolean(ParseState *pstate, Node **pnode);
79
80 extern Oid      select_common_type(List *typeids, const char *context);
81 extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
82                                           Oid targetTypeId,
83                                           const char *context);
84
85 #endif   /* PARSE_COERCE_H */