Re: drop if exists

From: Jari Aalto <jari(dot)aalto(at)cante(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: drop if exists
Date: 2005-10-15 08:35:20
Message-ID: zmpbuqif.fsf@blue.sea.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:

> Andrew Dunstan wrote:
>
| >
| > From time to time the suggestion crops up of allowing a DROP IF EXISTS
| > ... syntax. This seems not unreasonable, and I just spent a few minutes
| > looking at what might be involved.
>
> What about "CREATE IF NOT EXISTS" (CINE)? If we support DROP IF EXISTS
> (DIE), is the other one going to be supported too?
>
> How does this play with schemas? I assume DIE drops the table in any
> schema in the search path. What if there's more than one; drop the
> first one? CINE creates the schema in the first schema in the path,
> just like CREATE.
>
> Also, DIE does not need to lock the table afterwards because it won't
> exist, but CINE needs to keep a lock until transaction commit.

The "DROP IF EXISTS" is usually used in database creation scripts in
order to rebuild contents of schema. The parallel "CREATE IF EXISTS"
does not sound as useful feature.

DROP ... that table
CREATE ... that table

DROP ... that index
CREATE ... that index

etc.

It would also be MySQL compatible if DROP IF EXISTS were implemented.

Jari

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Satoshi Nagayasu 2005-10-15 11:02:37 Re: LDAP Authentication?
Previous Message 沈一枫 2005-10-15 08:32:51 tsearch2 sourcecode problem