pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Caune <daniel.caune@ubisoft.com>
To: pgsql-sql@postgresql.org
Subject: Using schema
Date: Fri, 30 Nov 2007 10:00:11 -0500
Message-ID: <1E293D3FF63A3740B10AD5AAD88535D2068E27F3@UBIMAIL1.ubisoft.org> (raw)

Hi,

I tried to figure out how to select a particular schema before executing
statement on its objects without having to specify the schema in these
statements (cf. the instruction USE supported in some other RDBMS)

PostgreSQL allows modifying dynamically the schema search path:

  SET search_path TO my_schema, public;

http://www.postgresql.org/docs/current/static/ddl-schemas.html
http://www.postgresql.org/docs/current/static/sql-set.html

By doing so, the creation statements will be executed in the schema
my_schema.

  SET search_path TO public;
  CREATE TABLE foo(i int);
  SET search_path TO my_schema, public;
  CREATE TABLE foo(i int);

             List of relations
  Schema   | Name  |   Type   |    Owner
-----------+------------------+-------------
 public    | bar   | table    | dbo_ubilive
 my_schema | foo   | table    | dbo_ubilive


The cool thing with this, compared to the USE statement supported by
some other RDBMS, is that the user is not restricted to one given schema
without explicit schema declaration:
 
  SELECT * FROM foo;                          -- Uses schema my_schema
  SELECT * FROM bar;                          -- Uses schema public
  SELECT * FROM foo, bar WHERE foo.i = bar.i; -- Uses both schemas

That is damn flexible! :-)

--
Daniel



view thread (2+ messages)  latest in thread

Message-ID: <1E293D3FF63A3740B10AD5AAD88535D2068E27F3@UBIMAIL1.ubisoft.org>
Permalink:  ../1E293D3FF63A3740B10AD5AAD88535D2068E27F3@UBIMAIL1.ubisoft.org/
Also on:    postgresql.org/message-id/1E293D3FF63A3740B10AD5AAD88535D2068E27F3@UBIMAIL1.ubisoft.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: daniel.caune@ubisoft.com
  Subject: Re: Using schema
  In-Reply-To: <1E293D3FF63A3740B10AD5AAD88535D2068E27F3@UBIMAIL1.ubisoft.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox