mirror of https://github.com/postgres/postgres
there and CREATE SCHEMA will make entries in it...ecpg_big_bison
parent
48c9164901
commit
a25b94c080
@ -0,0 +1,85 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_namespace.c |
||||
* routines to support manipulation of the pg_namespace relation |
||||
* |
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* |
||||
* IDENTIFICATION |
||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.1 2002/03/22 21:34:44 tgl Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#include "postgres.h" |
||||
|
||||
#include "access/heapam.h" |
||||
#include "catalog/catname.h" |
||||
#include "catalog/indexing.h" |
||||
#include "catalog/pg_namespace.h" |
||||
#include "miscadmin.h" |
||||
#include "utils/builtins.h" |
||||
#include "utils/syscache.h" |
||||
|
||||
|
||||
/* ----------------
|
||||
* NamespaceCreate |
||||
* --------------- |
||||
*/ |
||||
Oid |
||||
NamespaceCreate(const char *nspName) |
||||
{ |
||||
Relation nspdesc; |
||||
HeapTuple tup; |
||||
Oid nspoid; |
||||
char nulls[Natts_pg_namespace]; |
||||
Datum values[Natts_pg_namespace]; |
||||
NameData nname; |
||||
TupleDesc tupDesc; |
||||
int i; |
||||
|
||||
/* sanity checks */ |
||||
if (!nspName) |
||||
elog(ERROR, "no namespace name supplied"); |
||||
|
||||
/* make sure there is no existing namespace of same name */ |
||||
if (SearchSysCacheExists(NAMESPACENAME, |
||||
PointerGetDatum(nspName), |
||||
0, 0, 0)) |
||||
elog(ERROR, "namespace \"%s\" already exists", nspName); |
||||
|
||||
/* initialize nulls and values */ |
||||
for (i = 0; i < Natts_pg_namespace; i++) |
||||
{ |
||||
nulls[i] = ' '; |
||||
values[i] = (Datum) NULL; |
||||
} |
||||
namestrcpy(&nname, nspName); |
||||
values[Anum_pg_namespace_nspname - 1] = NameGetDatum(&nname); |
||||
values[Anum_pg_namespace_nspowner - 1] = Int32GetDatum(GetUserId()); |
||||
nulls[Anum_pg_namespace_nspacl - 1] = 'n'; |
||||
|
||||
nspdesc = heap_openr(NamespaceRelationName, RowExclusiveLock); |
||||
tupDesc = nspdesc->rd_att; |
||||
if (!HeapTupleIsValid(tup = heap_formtuple(tupDesc, |
||||
values, |
||||
nulls))) |
||||
elog(ERROR, "NamespaceCreate: heap_formtuple failed"); |
||||
nspoid = heap_insert(nspdesc, tup); |
||||
if (!OidIsValid(nspoid)) |
||||
elog(ERROR, "NamespaceCreate: heap_insert failed"); |
||||
|
||||
if (RelationGetForm(nspdesc)->relhasindex) |
||||
{ |
||||
Relation idescs[Num_pg_namespace_indices]; |
||||
|
||||
CatalogOpenIndices(Num_pg_namespace_indices, Name_pg_namespace_indices, idescs); |
||||
CatalogIndexInsert(idescs, Num_pg_namespace_indices, nspdesc, tup); |
||||
CatalogCloseIndices(Num_pg_namespace_indices, idescs); |
||||
} |
||||
|
||||
heap_close(nspdesc, RowExclusiveLock); |
||||
|
||||
return nspoid; |
||||
} |
@ -0,0 +1,79 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pg_namespace.h |
||||
* definition of the system "namespace" relation (pg_namespace) |
||||
* along with the relation's initial contents. |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* $Id: pg_namespace.h,v 1.1 2002/03/22 21:34:44 tgl Exp $ |
||||
* |
||||
* NOTES |
||||
* the genbki.sh script reads this file and generates .bki |
||||
* information from the DATA() statements. |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PG_NAMESPACE_H |
||||
#define PG_NAMESPACE_H |
||||
|
||||
/* ----------------
|
||||
* postgres.h contains the system type definitions and the |
||||
* CATALOG(), BOOTSTRAP and DATA() sugar words so this file |
||||
* can be read by both genbki.sh and the C compiler. |
||||
* ---------------- |
||||
*/ |
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* pg_namespace definition. |
||||
* |
||||
* cpp turns this into typedef struct FormData_pg_namespace |
||||
* |
||||
* nspname name of the namespace |
||||
* nspowner owner (creator) of the namespace |
||||
* nspacl access privilege list |
||||
* ---------------------------------------------------------------- |
||||
*/ |
||||
CATALOG(pg_namespace) |
||||
{ |
||||
NameData nspname; |
||||
int4 nspowner; |
||||
aclitem nspacl[1]; /* VARIABLE LENGTH FIELD */ |
||||
} FormData_pg_namespace; |
||||
|
||||
/* ----------------
|
||||
* Form_pg_namespace corresponds to a pointer to a tuple with |
||||
* the format of pg_namespace relation. |
||||
* ---------------- |
||||
*/ |
||||
typedef FormData_pg_namespace *Form_pg_namespace; |
||||
|
||||
/* ----------------
|
||||
* compiler constants for pg_namespace |
||||
* ---------------- |
||||
*/ |
||||
|
||||
#define Natts_pg_namespace 3 |
||||
#define Anum_pg_namespace_nspname 1 |
||||
#define Anum_pg_namespace_nspowner 2 |
||||
#define Anum_pg_namespace_nspacl 3 |
||||
|
||||
|
||||
/* ----------------
|
||||
* initial contents of pg_namespace |
||||
* --------------- |
||||
*/ |
||||
|
||||
DATA(insert OID = 11 ( "pg_catalog" PGUID "{=r}" )); |
||||
DESCR("System catalog namespace"); |
||||
#define PG_CATALOG_NAMESPACE 11 |
||||
|
||||
|
||||
/*
|
||||
* prototypes for functions in pg_namespace.c |
||||
*/ |
||||
extern Oid NamespaceCreate(const char *nspName); |
||||
|
||||
#endif /* PG_NAMESPACE_H */ |
Loading…
Reference in new issue