PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_cast.h File Reference
#include "catalog/dependency.h"
#include "catalog/genbki.h"
#include "catalog/pg_cast_d.h"
Include dependency graph for pg_cast.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef FormData_pg_castForm_pg_cast
 

Functions

 CATALOG (pg_cast, 2605, CastRelationId)
 
 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))
 
 MAKE_SYSCACHE (CASTSOURCETARGET, pg_cast_source_target_index, 256)
 
ObjectAddress CastCreate (Oid sourcetypeid, Oid targettypeid, Oid funcid, Oid incastid, Oid outcastid, char castcontext, char castmethod, DependencyType behavior)
 

Variables

 FormData_pg_cast
 

Typedef Documentation

◆ Form_pg_cast

Definition at line 57 of file pg_cast.h.

Function Documentation

◆ CastCreate()

ObjectAddress CastCreate ( Oid  sourcetypeid,
Oid  targettypeid,
Oid  funcid,
Oid  incastid,
Oid  outcastid,
char  castcontext,
char  castmethod,
DependencyType  behavior 
)
extern

Definition at line 49 of file pg_cast.c.

52{
53 Relation relation;
54 HeapTuple tuple;
55 Oid castid;
57 bool nulls[Natts_pg_cast] = {0};
60 ObjectAddresses *addrs;
61
63
64 /*
65 * Check for duplicate. This is just to give a friendly error message,
66 * the unique index would catch it anyway (so no need to sweat about race
67 * conditions).
68 */
72 if (HeapTupleIsValid(tuple))
75 errmsg("cast from type %s to type %s already exists",
78
79 /* ready to go */
87
88 tuple = heap_form_tuple(RelationGetDescr(relation), values, nulls);
89
90 CatalogTupleInsert(relation, tuple);
91
92 addrs = new_object_addresses();
93
94 /* make dependency entries */
96
97 /* dependency on source type */
100
101 /* dependency on target type */
104
105 /* dependency on function */
106 if (OidIsValid(funcid))
107 {
110 }
111
112 /* dependencies on casts required for function */
113 if (OidIsValid(incastid))
114 {
117 }
119 {
122 }
123
126
127 /* dependency on extension */
129
130 /* Post creation hook for new cast */
132
133 heap_freetuple(tuple);
134
135 table_close(relation, RowExclusiveLock);
136
137 return myself;
138}
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define OidIsValid(objectId)
Definition c.h:788
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:448
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
char * format_type_be(Oid type_oid)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition htup.h:78
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
#define RowExclusiveLock
Definition lockdefs.h:38
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define ObjectAddressSet(addr, class_id, object_id)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition pg_depend.c:193
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
static Datum CharGetDatum(char X)
Definition postgres.h:132
unsigned int Oid
static int fb(int x)
#define RelationGetDescr(relation)
Definition rel.h:540
#define ERRCODE_DUPLICATE_OBJECT
Definition streamutil.c:30
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition syscache.c:230
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References add_exact_object_address(), CatalogTupleInsert(), CharGetDatum(), ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, fb(), format_type_be(), free_object_addresses(), GetNewOidWithIndex(), heap_form_tuple(), heap_freetuple(), HeapTupleIsValid, InvokeObjectPostCreateHook, new_object_addresses(), ObjectAddressSet, ObjectIdGetDatum(), OidIsValid, record_object_address_dependencies(), recordDependencyOnCurrentExtension(), RelationGetDescr, RowExclusiveLock, SearchSysCache2(), table_close(), table_open(), and values.

Referenced by CreateCast(), and DefineRange().

◆ CATALOG()

CATALOG ( pg_cast  ,
2605  ,
CastRelationId   
)

Definition at line 32 of file pg_cast.h.

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;
#define BKI_LOOKUP(catalog)
Definition genbki.h:46
#define BKI_LOOKUP_OPT(catalog)
Definition genbki.h:47
FormData_pg_cast
Definition pg_cast.h:50

References BKI_LOOKUP, BKI_LOOKUP_OPT, and fb().

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_cast_source_target_index  ,
2661  ,
CastSourceTargetIndexId  ,
pg_cast  ,
btree(castsource oid_ops, casttarget oid_ops  
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_cast_oid_index  ,
2660  ,
CastOidIndexId  ,
pg_cast  ,
btree(oid oid_ops  
)

◆ MAKE_SYSCACHE()

MAKE_SYSCACHE ( CASTSOURCETARGET  ,
pg_cast_source_target_index  ,
256   
)

Variable Documentation

◆ FormData_pg_cast

FormData_pg_cast

Definition at line 50 of file pg_cast.h.