PostgreSQL Source Code  git master
pg_cast.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_cast.h
4  * definition of the "type casts" system catalog (pg_cast)
5  *
6  * As of Postgres 8.0, pg_cast describes not only type coercion functions
7  * but also length coercion functions.
8  *
9  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
10  * Portions Copyright (c) 1994, Regents of the University of California
11  *
12  * src/include/catalog/pg_cast.h
13  *
14  * NOTES
15  * The Catalog.pm module reads this file and derives schema
16  * information.
17  *
18  *-------------------------------------------------------------------------
19  */
20 #ifndef PG_CAST_H
21 #define PG_CAST_H
22 
23 #include "catalog/dependency.h"
24 #include "catalog/genbki.h"
25 #include "catalog/pg_cast_d.h"
26 
27 /* ----------------
28  * pg_cast definition. cpp turns this into
29  * typedef struct FormData_pg_cast
30  * ----------------
31  */
32 CATALOG(pg_cast,2605,CastRelationId)
33 {
34  Oid oid; /* oid */
35 
36  /* source datatype for cast */
37  Oid castsource BKI_LOOKUP(pg_type);
38 
39  /* destination datatype for cast */
40  Oid casttarget BKI_LOOKUP(pg_type);
41 
42  /* cast function; 0 = binary coercible */
43  Oid castfunc BKI_LOOKUP_OPT(pg_proc);
44 
45  /* contexts in which cast can be used */
46  char castcontext;
47 
48  /* cast method */
49  char castmethod;
51 
52 /* ----------------
53  * Form_pg_cast corresponds to a pointer to a tuple with
54  * the format of pg_cast relation.
55  * ----------------
56  */
58 
59 DECLARE_UNIQUE_INDEX_PKEY(pg_cast_oid_index, 2660, CastOidIndexId, on pg_cast using btree(oid oid_ops));
60 DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, CastSourceTargetIndexId, on pg_cast using btree(castsource oid_ops, casttarget oid_ops));
61 
62 #ifdef EXPOSE_TO_CLIENT_CODE
63 
64 /*
65  * The allowable values for pg_cast.castcontext are specified by this enum.
66  * Since castcontext is stored as a "char", we use ASCII codes for human
67  * convenience in reading the table. Note that internally to the backend,
68  * these values are converted to the CoercionContext enum (see primnodes.h),
69  * which is defined to sort in a convenient order; the ASCII codes don't
70  * have to sort in any special order.
71  */
72 
73 typedef enum CoercionCodes
74 {
75  COERCION_CODE_IMPLICIT = 'i', /* coercion in context of expression */
76  COERCION_CODE_ASSIGNMENT = 'a', /* coercion in context of assignment */
77  COERCION_CODE_EXPLICIT = 'e' /* explicit cast operation */
78 } CoercionCodes;
79 
80 /*
81  * The allowable values for pg_cast.castmethod are specified by this enum.
82  * Since castmethod is stored as a "char", we use ASCII codes for human
83  * convenience in reading the table.
84  */
85 typedef enum CoercionMethod
86 {
87  COERCION_METHOD_FUNCTION = 'f', /* use a function */
88  COERCION_METHOD_BINARY = 'b', /* types are binary-compatible */
89  COERCION_METHOD_INOUT = 'i' /* use input/output functions */
90 } CoercionMethod;
91 
92 #endif /* EXPOSE_TO_CLIENT_CODE */
93 
94 
95 extern ObjectAddress CastCreate(Oid sourcetypeid,
96  Oid targettypeid,
97  Oid funcid,
98  char castcontext,
99  char castmethod,
100  DependencyType behavior);
101 
102 #endif /* PG_CAST_H */
DependencyType
Definition: dependency.h:31
DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, CastSourceTargetIndexId, on pg_cast using btree(castsource oid_ops, casttarget oid_ops))
unsigned int Oid
Definition: postgres_ext.h:31
CATALOG(pg_cast, 2605, CastRelationId)
Definition: pg_cast.h:32
FormData_pg_cast
Definition: pg_cast.h:50
DECLARE_UNIQUE_INDEX_PKEY(pg_cast_oid_index, 2660, CastOidIndexId, on pg_cast using btree(oid oid_ops))
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
#define BKI_LOOKUP_OPT(catalog)
Definition: genbki.h:47
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
ObjectAddress CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext, char castmethod, DependencyType behavior)
Definition: pg_cast.c:43