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-2024, 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, pg_cast, btree(oid oid_ops));
60 DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, CastSourceTargetIndexId, pg_cast, btree(castsource oid_ops, casttarget oid_ops));
61 
62 MAKE_SYSCACHE(CASTSOURCETARGET, pg_cast_source_target_index, 256);
63 
64 #ifdef EXPOSE_TO_CLIENT_CODE
65 
66 /*
67  * The allowable values for pg_cast.castcontext are specified by this enum.
68  * Since castcontext is stored as a "char", we use ASCII codes for human
69  * convenience in reading the table. Note that internally to the backend,
70  * these values are converted to the CoercionContext enum (see primnodes.h),
71  * which is defined to sort in a convenient order; the ASCII codes don't
72  * have to sort in any special order.
73  */
74 
75 typedef enum CoercionCodes
76 {
77  COERCION_CODE_IMPLICIT = 'i', /* coercion in context of expression */
78  COERCION_CODE_ASSIGNMENT = 'a', /* coercion in context of assignment */
79  COERCION_CODE_EXPLICIT = 'e', /* explicit cast operation */
80 } CoercionCodes;
81 
82 /*
83  * The allowable values for pg_cast.castmethod are specified by this enum.
84  * Since castmethod is stored as a "char", we use ASCII codes for human
85  * convenience in reading the table.
86  */
87 typedef enum CoercionMethod
88 {
89  COERCION_METHOD_FUNCTION = 'f', /* use a function */
90  COERCION_METHOD_BINARY = 'b', /* types are binary-compatible */
91  COERCION_METHOD_INOUT = 'i', /* use input/output functions */
92 } CoercionMethod;
93 
94 #endif /* EXPOSE_TO_CLIENT_CODE */
95 
96 
97 extern ObjectAddress CastCreate(Oid sourcetypeid,
98  Oid targettypeid,
99  Oid funcid,
100  Oid incastid,
101  Oid outcastid,
102  char castcontext,
103  char castmethod,
104  DependencyType behavior);
105 
106 #endif /* PG_CAST_H */
DependencyType
Definition: dependency.h:32
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
#define BKI_LOOKUP_OPT(catalog)
Definition: genbki.h:47
CATALOG(pg_cast, 2605, CastRelationId)
Definition: pg_cast.h:32
DECLARE_UNIQUE_INDEX_PKEY(pg_cast_oid_index, 2660, CastOidIndexId, pg_cast, btree(oid oid_ops))
DECLARE_UNIQUE_INDEX(pg_cast_source_target_index, 2661, CastSourceTargetIndexId, pg_cast, btree(castsource oid_ops, casttarget oid_ops))
ObjectAddress CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, Oid incastid, Oid outcastid, char castcontext, char castmethod, DependencyType behavior)
Definition: pg_cast.c:49
MAKE_SYSCACHE(CASTSOURCETARGET, pg_cast_source_target_index, 256)
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
FormData_pg_cast
Definition: pg_cast.h:50
unsigned int Oid
Definition: postgres_ext.h:31