Commit 940f772a authored by Tom Lane's avatar Tom Lane

Support temporary setting of search path during CREATE SCHEMA; this

allows the example in the CREATE SCHEMA ref page to actually work now.
Also, clean up when the transaction that initially creates a temp-table
namespace is later aborted.  Simplify internal representation of search
path by folding special cases into the main list.
parent 5f21560a
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.121 2002/05/17 01:19:16 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.122 2002/05/17 20:53:33 tgl Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
......@@ -164,6 +164,7 @@
#include "access/xact.h"
#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/namespace.h"
#include "commands/async.h"
#include "commands/sequence.h"
#include "commands/trigger.h"
......@@ -1009,6 +1010,7 @@ CommitTransaction(void)
AtEOXact_hash();
AtEOXact_nbtree();
AtEOXact_rtree();
AtEOXact_Namespace(true);
AtCommit_Cache();
AtCommit_Locks();
AtEOXact_CatCache(true);
......@@ -1112,6 +1114,7 @@ AbortTransaction(void)
AtEOXact_hash();
AtEOXact_nbtree();
AtEOXact_rtree();
AtEOXact_Namespace(false);
AtAbort_Cache();
AtEOXact_CatCache(false);
AtAbort_Memory();
......
This diff is collapsed.
......@@ -8,13 +8,14 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.2 2002/04/27 03:45:01 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.3 2002/05/17 20:53:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_namespace.h"
#include "commands/schemacmds.h"
#include "miscadmin.h"
......@@ -32,6 +33,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
{
const char *schemaName = stmt->schemaname;
const char *authId = stmt->authid;
Oid namespaceId;
List *parsetree_list;
List *parsetree_item;
const char *owner_name;
......@@ -85,11 +87,18 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
schemaName);
/* Create the schema's namespace */
NamespaceCreate(schemaName, owner_userid);
namespaceId = NamespaceCreate(schemaName, owner_userid);
/* Let commands in the schema-element-list know about the schema */
/* Advance cmd counter to make the namespace visible */
CommandCounterIncrement();
/*
* Temporarily make the new namespace be the front of the search path,
* as well as the default creation target namespace. This will be undone
* at the end of this routine, or upon error.
*/
PushSpecialNamespace(namespaceId);
/*
* Examine the list of commands embedded in the CREATE SCHEMA command,
* and reorganize them into a sequentially executable order with no
......@@ -124,6 +133,9 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
}
}
/* Reset search path to normal state */
PopSpecialNamespace(namespaceId);
/* Reset current user */
SetUserId(saved_userid);
}
......@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.34 2002/04/26 01:24:08 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/name.c,v 1.35 2002/05/17 20:53:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -235,7 +235,7 @@ session_user(PG_FUNCTION_ARGS)
Datum
current_schema(PG_FUNCTION_ARGS)
{
List *search_path = fetch_search_path();
List *search_path = fetch_search_path(false);
char *nspname;
if (search_path == NIL)
......@@ -247,7 +247,7 @@ current_schema(PG_FUNCTION_ARGS)
Datum
current_schemas(PG_FUNCTION_ARGS)
{
List *search_path = fetch_search_path();
List *search_path = fetch_search_path(false);
int nnames = length(search_path);
Datum *names;
int i;
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: namespace.h,v 1.13 2002/05/17 01:19:19 tgl Exp $
* $Id: namespace.h,v 1.14 2002/05/17 20:53:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -72,13 +72,19 @@ extern char *NameListToString(List *names);
extern bool isTempNamespace(Oid namespaceId);
extern void PushSpecialNamespace(Oid namespaceId);
extern void PopSpecialNamespace(Oid namespaceId);
/* initialization & transaction cleanup code */
extern void InitializeSearchPath(void);
extern void AtEOXact_Namespace(bool isCommit);
/* stuff for search_path GUC variable */
extern char *namespace_search_path;
extern const char *assign_search_path(const char *newval,
bool doit, bool interactive);
extern void InitializeSearchPath(void);
extern List *fetch_search_path(void);
extern List *fetch_search_path(bool includeImplicit);
#endif /* NAMESPACE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment