1 /*-------------------------------------------------------------------------
4 * routines to support manipulation of the pg_namespace relation
6 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL: pgsql/src/backend/catalog/pg_namespace.c,v 1.13 2005/04/14 20:03:23 tgl Exp $
13 *-------------------------------------------------------------------------
17 #include "access/heapam.h"
18 #include "catalog/indexing.h"
19 #include "catalog/pg_namespace.h"
20 #include "utils/builtins.h"
21 #include "utils/syscache.h"
29 NamespaceCreate(const char *nspName, int32 ownerSysId)
34 char nulls[Natts_pg_namespace];
35 Datum values[Natts_pg_namespace];
42 elog(ERROR, "no namespace name supplied");
44 /* make sure there is no existing namespace of same name */
45 if (SearchSysCacheExists(NAMESPACENAME,
46 PointerGetDatum(nspName),
49 (errcode(ERRCODE_DUPLICATE_SCHEMA),
50 errmsg("schema \"%s\" already exists", nspName)));
52 /* initialize nulls and values */
53 for (i = 0; i < Natts_pg_namespace; i++)
56 values[i] = (Datum) NULL;
58 namestrcpy(&nname, nspName);
59 values[Anum_pg_namespace_nspname - 1] = NameGetDatum(&nname);
60 values[Anum_pg_namespace_nspowner - 1] = Int32GetDatum(ownerSysId);
61 nulls[Anum_pg_namespace_nspacl - 1] = 'n';
63 nspdesc = heap_open(NamespaceRelationId, RowExclusiveLock);
64 tupDesc = nspdesc->rd_att;
66 tup = heap_formtuple(tupDesc, values, nulls);
68 nspoid = simple_heap_insert(nspdesc, tup);
69 Assert(OidIsValid(nspoid));
71 CatalogUpdateIndexes(nspdesc, tup);
73 heap_close(nspdesc, RowExclusiveLock);