PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_namespace.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_namespace.h"
#include "utils/builtins.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Include dependency graph for pg_namespace.c:

Go to the source code of this file.

Functions

Oid NamespaceCreate (const char *nspName, Oid ownerId, bool isTemp)
 

Function Documentation

◆ NamespaceCreate()

Oid NamespaceCreate ( const char nspName,
Oid  ownerId,
bool  isTemp 
)

Definition at line 43 of file pg_namespace.c.

44{
47 Oid nspoid;
48 bool nulls[Natts_pg_namespace];
51 TupleDesc tupDesc;
53 int i;
54 Acl *nspacl;
55
56 /* sanity checks */
57 if (!nspName)
58 elog(ERROR, "no namespace name supplied");
59
60 /* make sure there is no existing namespace of same name */
64 errmsg("schema \"%s\" already exists", nspName)));
65
66 if (!isTemp)
69 else
70 nspacl = NULL;
71
73 tupDesc = nspdesc->rd_att;
74
75 /* initialize nulls and values */
76 for (i = 0; i < Natts_pg_namespace; i++)
77 {
78 nulls[i] = false;
79 values[i] = (Datum) 0;
80 }
81
88 if (nspacl != NULL)
90 else
91 nulls[Anum_pg_namespace_nspacl - 1] = true;
92
93
94 tup = heap_form_tuple(tupDesc, values, nulls);
95
98
100
101 /* Record dependencies */
102 myself.classId = NamespaceRelationId;
103 myself.objectId = nspoid;
104 myself.objectSubId = 0;
105
106 /* dependency on owner */
108
109 /* dependencies on roles mentioned in default ACL */
111
112 /* dependency on extension ... but not for magic temp schemas */
113 if (!isTemp)
115
116 /* Post creation hook for new schema */
118
119 return nspoid;
120}
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
Definition aclchk.c:4327
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
Definition aclchk.c:4247
static Datum values[MAXATTR]
Definition bootstrap.c:155
#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
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
int i
Definition isn.c:77
#define RowExclusiveLock
Definition lockdefs.h:38
void namestrcpy(Name name, const char *str)
Definition name.c:233
#define InvokeObjectPostCreateHook(classId, objectId, subId)
@ OBJECT_SCHEMA
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition pg_depend.c:193
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
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
#define InvalidOid
unsigned int Oid
static int fb(int x)
Definition c.h:760
#define SearchSysCacheExists1(cacheId, key1)
Definition syscache.h:100
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References Assert, CatalogTupleInsert(), elog, ereport, errcode(), errmsg(), ERROR, fb(), get_user_default_acl(), GetNewOidWithIndex(), heap_form_tuple(), i, InvalidOid, InvokeObjectPostCreateHook, NameGetDatum(), namestrcpy(), OBJECT_SCHEMA, ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), recordDependencyOnCurrentExtension(), recordDependencyOnNewAcl(), recordDependencyOnOwner(), RowExclusiveLock, SearchSysCacheExists1, table_close(), table_open(), and values.

Referenced by CreateSchemaCommand(), and InitTempTableNamespace().