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-2020, 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(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 #ifdef EXPOSE_TO_CLIENT_CODE
60 
61 /*
62  * The allowable values for pg_cast.castcontext are specified by this enum.
63  * Since castcontext is stored as a "char", we use ASCII codes for human
64  * convenience in reading the table. Note that internally to the backend,
65  * these values are converted to the CoercionContext enum (see primnodes.h),
66  * which is defined to sort in a convenient order; the ASCII codes don't
67  * have to sort in any special order.
68  */
69 
70 typedef enum CoercionCodes
71 {
72  COERCION_CODE_IMPLICIT = 'i', /* coercion in context of expression */
73  COERCION_CODE_ASSIGNMENT = 'a', /* coercion in context of assignment */
74  COERCION_CODE_EXPLICIT = 'e' /* explicit cast operation */
75 } CoercionCodes;
76 
77 /*
78  * The allowable values for pg_cast.castmethod are specified by this enum.
79  * Since castmethod is stored as a "char", we use ASCII codes for human
80  * convenience in reading the table.
81  */
82 typedef enum CoercionMethod
83 {
84  COERCION_METHOD_FUNCTION = 'f', /* use a function */
85  COERCION_METHOD_BINARY = 'b', /* types are binary-compatible */
86  COERCION_METHOD_INOUT = 'i' /* use input/output functions */
87 } CoercionMethod;
88 
89 #endif /* EXPOSE_TO_CLIENT_CODE */
90 
91 
92 extern ObjectAddress CastCreate(Oid sourcetypeid,
93  Oid targettypeid,
94  Oid funcid,
95  char castcontext,
96  char castmethod,
97  DependencyType behavior);
98 
99 #endif /* PG_CAST_H */
DependencyType
Definition: dependency.h:31
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
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
#define BKI_LOOKUP(catalog)
Definition: genbki.h:42
ObjectAddress CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext, char castmethod, DependencyType behavior)
Definition: pg_cast.c:43