Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "postgres.h"
00016
00017 #include "access/heapam.h"
00018 #include "access/htup_details.h"
00019 #include "catalog/dependency.h"
00020 #include "catalog/indexing.h"
00021 #include "catalog/objectaccess.h"
00022 #include "catalog/pg_namespace.h"
00023 #include "utils/builtins.h"
00024 #include "utils/rel.h"
00025 #include "utils/syscache.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 Oid
00041 NamespaceCreate(const char *nspName, Oid ownerId, bool isTemp)
00042 {
00043 Relation nspdesc;
00044 HeapTuple tup;
00045 Oid nspoid;
00046 bool nulls[Natts_pg_namespace];
00047 Datum values[Natts_pg_namespace];
00048 NameData nname;
00049 TupleDesc tupDesc;
00050 ObjectAddress myself;
00051 int i;
00052
00053
00054 if (!nspName)
00055 elog(ERROR, "no namespace name supplied");
00056
00057
00058 if (SearchSysCacheExists1(NAMESPACENAME, PointerGetDatum(nspName)))
00059 ereport(ERROR,
00060 (errcode(ERRCODE_DUPLICATE_SCHEMA),
00061 errmsg("schema \"%s\" already exists", nspName)));
00062
00063
00064 for (i = 0; i < Natts_pg_namespace; i++)
00065 {
00066 nulls[i] = false;
00067 values[i] = (Datum) NULL;
00068 }
00069 namestrcpy(&nname, nspName);
00070 values[Anum_pg_namespace_nspname - 1] = NameGetDatum(&nname);
00071 values[Anum_pg_namespace_nspowner - 1] = ObjectIdGetDatum(ownerId);
00072 nulls[Anum_pg_namespace_nspacl - 1] = true;
00073
00074 nspdesc = heap_open(NamespaceRelationId, RowExclusiveLock);
00075 tupDesc = nspdesc->rd_att;
00076
00077 tup = heap_form_tuple(tupDesc, values, nulls);
00078
00079 nspoid = simple_heap_insert(nspdesc, tup);
00080 Assert(OidIsValid(nspoid));
00081
00082 CatalogUpdateIndexes(nspdesc, tup);
00083
00084 heap_close(nspdesc, RowExclusiveLock);
00085
00086
00087 myself.classId = NamespaceRelationId;
00088 myself.objectId = nspoid;
00089 myself.objectSubId = 0;
00090
00091
00092 recordDependencyOnOwner(NamespaceRelationId, nspoid, ownerId);
00093
00094
00095 if (!isTemp)
00096 recordDependencyOnCurrentExtension(&myself, false);
00097
00098
00099 InvokeObjectPostCreateHook(NamespaceRelationId, nspoid, 0);
00100
00101 return nspoid;
00102 }