PostgreSQL Source Code: src/backend/commands/schemacmds.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
39
41
42
43
44
45
46
47
48
49
50
53 int stmt_location, int stmt_len)
54{
55 const char *schemaName = stmt->schemaname;
56 Oid namespaceId;
57 List *parsetree_list;
59 Oid owner_uid;
60 Oid saved_uid;
61 int save_sec_context;
62 int save_nestlevel;
67
69
70
71
72
73 if (stmt->authrole)
75 else
76 owner_uid = saved_uid;
77
78
79 if (!schemaName)
80 {
82
85 elog(ERROR, "cache lookup failed for role %u", owner_uid);
86 schemaName =
89 }
90
91
92
93
94
95
96
97
102
104
105
108 (errcode(ERRCODE_RESERVED_NAME),
109 errmsg("unacceptable schema name \"%s\"", schemaName),
110 errdetail("The prefix \"pg_\" is reserved for system schemas.")));
111
112
113
114
115
116
117
118
119 if (stmt->if_not_exists)
120 {
123 {
124
125
126
127
130
131
133 (errcode(ERRCODE_DUPLICATE_SCHEMA),
134 errmsg("schema \"%s\" already exists, skipping",
135 schemaName)));
137 }
138 }
139
140
141
142
143
144
145
146
147
148 if (saved_uid != owner_uid)
151
152
153 namespaceId = NamespaceCreate(schemaName, owner_uid, false);
154
155
157
158
159
160
161
162
163
164
166
169
171 nsp++;
172
173 if (*nsp != '\0')
175
179
180
181
182
183
184
185
189
190
191
192
193
194
195
196
198 schemaName);
199
200
201
202
203
204
205
206 foreach(parsetree_item, parsetree_list)
207 {
210
211
217 wrapper->stmt_len = stmt_len;
218
219
221 queryString,
222 false,
224 NULL,
225 NULL,
227 NULL);
228
229
231 }
232
233
234
235
237
238
240
241 return namespaceId;
242}
243
244
245
246
247
250{
251 Oid nspOid;
257
259
263 (errcode(ERRCODE_UNDEFINED_SCHEMA),
264 errmsg("schema \"%s\" does not exist", oldname)));
265
267 nspOid = nspform->oid;
268
269
272 (errcode(ERRCODE_DUPLICATE_SCHEMA),
273 errmsg("schema \"%s\" already exists", newname)));
274
275
278 oldname);
279
280
285
288 (errcode(ERRCODE_RESERVED_NAME),
289 errmsg("unacceptable schema name \"%s\"", newname),
290 errdetail("The prefix \"pg_\" is reserved for system schemas.")));
291
292
293 namestrcpy(&nspform->nspname, newname);
295
297
299
302
303 return address;
304}
305
306void
308{
311
313
316 elog(ERROR, "cache lookup failed for schema %u", schemaoid);
317
319
321
323}
324
325
326
327
328
331{
332 Oid nspOid;
337
339
343 (errcode(ERRCODE_UNDEFINED_SCHEMA),
344 errmsg("schema \"%s\" does not exist", name)));
345
347 nspOid = nspform->oid;
348
350
352
354
356
357 return address;
358}
359
360static void
362{
364
367
369
370
371
372
373
374 if (nspForm->nspowner != newOwnerId)
375 {
376 Datum repl_val[Natts_pg_namespace];
377 bool repl_null[Natts_pg_namespace];
378 bool repl_repl[Natts_pg_namespace];
379 Acl *newAcl;
381 bool isNull;
384
385
388 NameStr(nspForm->nspname));
389
390
392
393
394
395
396
397
398
399
400
401
407
408 memset(repl_null, false, sizeof(repl_null));
409 memset(repl_repl, false, sizeof(repl_repl));
410
411 repl_repl[Anum_pg_namespace_nspowner - 1] = true;
412 repl_val[Anum_pg_namespace_nspowner - 1] = ObjectIdGetDatum(newOwnerId);
413
414
415
416
417
419 Anum_pg_namespace_nspacl,
420 &isNull);
421 if (!isNull)
422 {
424 nspForm->nspowner, newOwnerId);
425 repl_repl[Anum_pg_namespace_nspacl - 1] = true;
426 repl_val[Anum_pg_namespace_nspacl - 1] = PointerGetDatum(newAcl);
427 }
428
430
432
434
435
437 newOwnerId);
438 }
439
441 nspForm->oid, 0);
442}
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
#define OidIsValid(objectId)
bool IsReservedName(const char *name)
char * get_database_name(Oid dbid)
DestReceiver * None_Receiver
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
bool allowSystemTableMods
int NewGUCNestLevel(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
char * pstrdup(const char *in)
#define SECURITY_LOCAL_USERID_CHANGE
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void SetUserIdAndSecContext(Oid userid, int sec_context)
void namestrcpy(Name name, const char *str)
Oid get_namespace_oid(const char *nspname, bool missing_ok)
char * namespace_search_path
#define InvokeObjectPostAlterHook(classId, objectId, subId)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
List * transformCreateSchemaStmtElements(List *schemaElts, const char *schemaName)
FormData_pg_authid * Form_pg_authid
void checkMembershipInCurrentExtension(const ObjectAddress *object)
Oid NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
FormData_pg_namespace * Form_pg_namespace
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
const char * quote_identifier(const char *ident)
bool scanner_isspace(char ch)
Oid CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString, int stmt_location, int stmt_len)
void AlterSchemaOwner_oid(Oid schemaoid, Oid newOwnerId)
ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId)
ObjectAddress RenameSchema(const char *oldname, const char *newname)
static void AlterSchemaOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
#define SearchSysCacheCopy1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
@ PROCESS_UTILITY_SUBCOMMAND
void CommandCounterIncrement(void)