]> granicus.if.org Git - postgresql/blob - src/include/parser/parse_coerce.h
Replace the hard-wired type knowledge in TypeCategory() and IsPreferredType()
[postgresql] / src / include / parser / parse_coerce.h
1 /*-------------------------------------------------------------------------
2  *
3  * parse_coerce.h
4  *      Routines for type coercion.
5  *
6  *
7  * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/parser/parse_coerce.h,v 1.76 2008/07/30 17:05:05 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PARSE_COERCE_H
15 #define PARSE_COERCE_H
16
17 #include "parser/parse_node.h"
18
19
20 /* Type categories (see TYPCATEGORY_xxx symbols in catalog/pg_type.h) */
21 typedef char TYPCATEGORY;
22
23 /* Result codes for find_coercion_pathway */
24 typedef enum CoercionPathType
25 {
26         COERCION_PATH_NONE,                     /* failed to find any coercion pathway */
27         COERCION_PATH_FUNC,                     /* apply the specified coercion function */
28         COERCION_PATH_RELABELTYPE,      /* binary-compatible cast, no function */
29         COERCION_PATH_ARRAYCOERCE,      /* need an ArrayCoerceExpr node */
30         COERCION_PATH_COERCEVIAIO       /* need a CoerceViaIO node */
31 } CoercionPathType;
32
33
34 extern bool IsBinaryCoercible(Oid srctype, Oid targettype);
35 extern bool IsPreferredType(TYPCATEGORY category, Oid type);
36 extern TYPCATEGORY TypeCategory(Oid type);
37
38 extern Node *coerce_to_target_type(ParseState *pstate,
39                                           Node *expr, Oid exprtype,
40                                           Oid targettype, int32 targettypmod,
41                                           CoercionContext ccontext,
42                                           CoercionForm cformat);
43 extern bool can_coerce_type(int nargs, Oid *input_typeids, Oid *target_typeids,
44                                 CoercionContext ccontext);
45 extern Node *coerce_type(ParseState *pstate, Node *node,
46                         Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod,
47                         CoercionContext ccontext, CoercionForm cformat);
48 extern Node *coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod,
49                                  Oid typeId,
50                                  CoercionForm cformat, bool hideInputCoercion,
51                                  bool lengthCoercionDone);
52
53 extern Node *coerce_to_boolean(ParseState *pstate, Node *node,
54                                   const char *constructName);
55 extern Node *coerce_to_specific_type(ParseState *pstate, Node *node,
56                                                 Oid targetTypeId,
57                                                 const char *constructName);
58
59 extern Oid      select_common_type(List *typeids, const char *context);
60 extern Node *coerce_to_common_type(ParseState *pstate, Node *node,
61                                           Oid targetTypeId,
62                                           const char *context);
63
64 extern bool check_generic_type_consistency(Oid *actual_arg_types,
65                                                            Oid *declared_arg_types,
66                                                            int nargs);
67 extern Oid enforce_generic_type_consistency(Oid *actual_arg_types,
68                                                                  Oid *declared_arg_types,
69                                                                  int nargs,
70                                                                  Oid rettype,
71                                                                  bool allow_poly);
72 extern Oid resolve_generic_type(Oid declared_type,
73                                          Oid context_actual_type,
74                                          Oid context_declared_type);
75
76 extern CoercionPathType find_coercion_pathway(Oid targetTypeId,
77                                           Oid sourceTypeId,
78                                           CoercionContext ccontext,
79                                           Oid *funcid);
80 extern CoercionPathType find_typmod_coercion_function(Oid typeId,
81                                                           Oid *funcid);
82
83 #endif   /* PARSE_COERCE_H */