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

Go to the source code of this file.

Typedefs

typedef FormData_pg_collationForm_pg_collation
 

Functions

 CATALOG (pg_collation, 3456, CollationRelationId)
 
 DECLARE_TOAST (pg_collation, 6175, 6176)
 
 DECLARE_UNIQUE_INDEX (pg_collation_name_enc_nsp_index, 3164, CollationNameEncNspIndexId, pg_collation, btree(collname name_ops, collencoding int4_ops, collnamespace oid_ops))
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_collation_oid_index, 3085, CollationOidIndexId, pg_collation, btree(oid oid_ops))
 
 MAKE_SYSCACHE (COLLNAMEENCNSP, pg_collation_name_enc_nsp_index, 8)
 
 MAKE_SYSCACHE (COLLOID, pg_collation_oid_index, 8)
 
Oid CollationCreate (const char *collname, Oid collnamespace, Oid collowner, char collprovider, bool collisdeterministic, int32 collencoding, const char *collcollate, const char *collctype, const char *colllocale, const char *collicurules, const char *collversion, bool if_not_exists, bool quiet)
 

Variables

 FormData_pg_collation
 

Typedef Documentation

◆ Form_pg_collation

Function Documentation

◆ CATALOG()

CATALOG ( pg_collation  ,
3456  ,
CollationRelationId   
)

Definition at line 29 of file pg_collation.h.

30{
31 Oid oid; /* oid */
32 NameData collname; /* collation name */
33
34 /* OID of namespace containing this collation */
36
37 /* owner of collation */
39 char collprovider; /* see constants below */
41 int32 collencoding; /* encoding for this collation; -1 = "all" */
42#ifdef CATALOG_VARLEN /* variable-length fields start here */
43 text collcollate BKI_DEFAULT(_null_); /* LC_COLLATE setting */
44 text collctype BKI_DEFAULT(_null_); /* LC_CTYPE setting */
45 text colllocale BKI_DEFAULT(_null_); /* locale ID */
46 text collicurules BKI_DEFAULT(_null_); /* ICU collation rules */
47 text collversion BKI_DEFAULT(_null_); /* provider-dependent
48 * version of collation
49 * data */
50#endif
int32_t int32
Definition c.h:542
#define BKI_LOOKUP(catalog)
Definition genbki.h:46
#define BKI_DEFAULT(value)
Definition genbki.h:35
FormData_pg_collation
unsigned int Oid
static int fb(int x)
Definition c.h:760
Definition c.h:706

References BKI_DEFAULT, BKI_LOOKUP, and fb().

◆ CollationCreate()

Oid CollationCreate ( const char collname,
Oid  collnamespace,
Oid  collowner,
char  collprovider,
bool  collisdeterministic,
int32  collencoding,
const char collcollate,
const char collctype,
const char colllocale,
const char collicurules,
const char collversion,
bool  if_not_exists,
bool  quiet 
)
extern

Definition at line 42 of file pg_collation.c.

53{
54 Relation rel;
55 TupleDesc tupDesc;
58 bool nulls[Natts_pg_collation];
60 Oid oid;
63
64 Assert(collname);
71
72 /*
73 * Make sure there is no existing collation of same name & encoding.
74 *
75 * This would be caught by the unique index anyway; we're just giving a
76 * friendlier error message. The unique index provides a backstop against
77 * race conditions.
78 */
81 PointerGetDatum(collname),
82 Int32GetDatum(collencoding),
84 if (OidIsValid(oid))
85 {
86 if (quiet)
87 return InvalidOid;
88 else if (if_not_exists)
89 {
90 /*
91 * If we are in an extension script, insist that the pre-existing
92 * object be a member of the extension, to avoid security risks.
93 */
96
97 /* OK to skip */
100 collencoding == -1
101 ? errmsg("collation \"%s\" already exists, skipping",
102 collname)
103 : errmsg("collation \"%s\" for encoding \"%s\" already exists, skipping",
104 collname, pg_encoding_to_char(collencoding))));
105 return InvalidOid;
106 }
107 else
110 collencoding == -1
111 ? errmsg("collation \"%s\" already exists",
112 collname)
113 : errmsg("collation \"%s\" for encoding \"%s\" already exists",
114 collname, pg_encoding_to_char(collencoding))));
115 }
116
117 /* open pg_collation; see below about the lock level */
119
120 /*
121 * Also forbid a specific-encoding collation shadowing an any-encoding
122 * collation, or an any-encoding collation being shadowed (see
123 * get_collation_name()). This test is not backed up by the unique index,
124 * so we take a ShareRowExclusiveLock earlier, to protect against
125 * concurrent changes fooling this check.
126 */
127 if (collencoding == -1)
130 PointerGetDatum(collname),
133 else
136 PointerGetDatum(collname),
137 Int32GetDatum(-1),
139 if (OidIsValid(oid))
140 {
141 if (quiet)
142 {
143 table_close(rel, NoLock);
144 return InvalidOid;
145 }
146 else if (if_not_exists)
147 {
148 /*
149 * If we are in an extension script, insist that the pre-existing
150 * object be a member of the extension, to avoid security risks.
151 */
154
155 /* OK to skip */
156 table_close(rel, NoLock);
159 errmsg("collation \"%s\" already exists, skipping",
160 collname)));
161 return InvalidOid;
162 }
163 else
166 errmsg("collation \"%s\" already exists",
167 collname)));
168 }
169
170 tupDesc = RelationGetDescr(rel);
171
172 /* form a tuple */
173 memset(nulls, 0, sizeof(nulls));
174
175 namestrcpy(&name_name, collname);
185 if (collcollate)
187 else
188 nulls[Anum_pg_collation_collcollate - 1] = true;
189 if (collctype)
191 else
192 nulls[Anum_pg_collation_collctype - 1] = true;
193 if (colllocale)
195 else
196 nulls[Anum_pg_collation_colllocale - 1] = true;
197 if (collicurules)
199 else
200 nulls[Anum_pg_collation_collicurules - 1] = true;
201 if (collversion)
203 else
204 nulls[Anum_pg_collation_collversion - 1] = true;
205
206 tup = heap_form_tuple(tupDesc, values, nulls);
207
208 /* insert a new tuple */
210 Assert(OidIsValid(oid));
211
212 /* set up dependencies for the new collation */
213 myself.classId = CollationRelationId;
214 myself.objectId = oid;
215 myself.objectSubId = 0;
216
217 /* create dependency on namespace */
219 referenced.objectId = collnamespace;
220 referenced.objectSubId = 0;
222
223 /* create dependency on owner */
225
226 /* dependency on extension */
228
229 /* Post creation hook for new collation */
231
233 table_close(rel, NoLock);
234
235 return oid;
236}
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:97
#define Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:448
@ DEPENDENCY_NORMAL
Definition dependency.h:33
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define NOTICE
Definition elog.h:35
#define ereport(elevel,...)
Definition elog.h:150
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
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
#define NoLock
Definition lockdefs.h:34
#define ShareRowExclusiveLock
Definition lockdefs.h:41
int GetDatabaseEncoding(void)
Definition mbutils.c:1264
void namestrcpy(Name name, const char *str)
Definition name.c:233
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define ObjectAddressSet(addr, class_id, object_id)
void checkMembershipInCurrentExtension(const ObjectAddress *object)
Definition pg_depend.c:258
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition pg_depend.c:45
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition pg_depend.c:193
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
#define pg_encoding_to_char
Definition pg_wchar.h:630
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static Datum NameGetDatum(const NameData *X)
Definition postgres.h:403
uint64_t Datum
Definition postgres.h:70
static Datum Int32GetDatum(int32 X)
Definition postgres.h:222
static Datum CharGetDatum(char X)
Definition postgres.h:132
#define InvalidOid
#define RelationGetDescr(relation)
Definition rel.h:540
#define ERRCODE_DUPLICATE_OBJECT
Definition streamutil.c:30
#define GetSysCacheOid3(cacheId, oidcol, key1, key2, key3)
Definition syscache.h:113
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References Assert, BoolGetDatum(), CatalogTupleInsert(), CharGetDatum(), checkMembershipInCurrentExtension(), CStringGetTextDatum, DEPENDENCY_NORMAL, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, fb(), GetDatabaseEncoding(), GetNewOidWithIndex(), GetSysCacheOid3, heap_form_tuple(), heap_freetuple(), Int32GetDatum(), InvalidOid, InvokeObjectPostCreateHook, NameGetDatum(), namestrcpy(), NoLock, NOTICE, ObjectAddressSet, ObjectIdGetDatum(), OidIsValid, pg_encoding_to_char, PointerGetDatum(), recordDependencyOn(), recordDependencyOnCurrentExtension(), recordDependencyOnOwner(), RelationGetDescr, ShareRowExclusiveLock, table_close(), table_open(), and values.

Referenced by DefineCollation(), and pg_import_system_collations().

◆ DECLARE_TOAST()

DECLARE_TOAST ( pg_collation  ,
6175  ,
6176   
)

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_collation_name_enc_nsp_index  ,
3164  ,
CollationNameEncNspIndexId  ,
pg_collation  ,
btree(collname name_ops, collencoding int4_ops, collnamespace oid_ops  
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_collation_oid_index  ,
3085  ,
CollationOidIndexId  ,
pg_collation  ,
btree(oid oid_ops  
)

◆ MAKE_SYSCACHE() [1/2]

MAKE_SYSCACHE ( COLLNAMEENCNSP  ,
pg_collation_name_enc_nsp_index  ,
 
)

◆ MAKE_SYSCACHE() [2/2]

MAKE_SYSCACHE ( COLLOID  ,
pg_collation_oid_index  ,
 
)

Variable Documentation

◆ FormData_pg_collation

FormData_pg_collation

Definition at line 51 of file pg_collation.h.