Skip site navigation (1) Skip section navigation (2)

Re: CREATE SCHEMA IF NOT EXISTS

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: David E(dot) Wheeler <david(at)justatheory(dot)com>
Cc: Dickson S(dot) Guedes <listas(at)guedesoft(dot)net>, fabriziomello <fabriziomello(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: CREATE SCHEMA IF NOT EXISTS
Date: 2012-10-02 19:52:15
Message-ID: 1349207179-sup-9461@alvh.no-ip.org (view raw or flat)
Thread:
Lists: pgsql-hackers
Excerpts from David E. Wheeler's message of mar oct 02 16:37:30 -0300 2012:
> On Oct 2, 2012, at 12:30 PM, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> 
> > How about call this for precedent:
> > 
> > mkdir -p /tmp/foo/bar
> > mkdir -p /tmp/foo/baz
> > 
> > In this case you end up with directory "foo" and at least two subdirs in
> > it, bar and baz.  This works even if /tmp/foo existed previously and
> > even if there was some other stuff in it.
> 
> Well, what about this, then?
> 
> create schema if not exists foo create table second (a int);
> create schema if not exists foo create table second (b int);

Yes, exactly -- what about this case?  This is precisely the reason we
don't have CREATE TABLE IF NOT EXISTS.

I don't know what the best answer is.  Most people seem to think that
the answer ought to be that you end up with a single column second.a,
and the second command errors out.

So if you do this:

create schema if not exists foo create table first (a int);
create schema if not exists foo create table first (b int),
                                create table second (a int);

you end up with *only* the first table, because the second command
errors out when the first table is observed to exist.

Now, what if you were to do this instead:

create schema if not exists foo
   create table if not exists first (a int);
create schema if not exists foo
   create table if not exists first (b int),
   create table if not exists second (a int);

The you end up with first.a and second.a.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


In response to

pgsql-hackers by date

Next:From: David E. WheelerDate: 2012-10-02 19:54:21
Subject: Re: CREATE SCHEMA IF NOT EXISTS
Previous:From: Tom LaneDate: 2012-10-02 19:48:33
Subject: Re: CREATE SCHEMA IF NOT EXISTS

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group