drop if exists - first piece

Lists: pgsql-patches
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: drop if exists - first piece
Date: 2005-11-18 22:42:36
Message-ID: 437E58DC.2090700@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches


I will apply the attached patch tomorrow, barring objection. This covers
drop if exists for the following objects:

table view index sequence schema type domain conversion

I have a simple test script as show below, but I am not sure where to
put it in the regression tests - add a new one maybe? The test for each
object proves that the object doesn't exist, shows that we don't
generate an error using IF EXISTS when it doesn't exist, and then shows
that we do drop the object properly if it does exist.

cheers

andrew

--
-- IF EXISTS tests
--

-- table (will be really dropped at the end)

DROP TABLE test_exists;

DROP TABLE IF EXISTS test_exists;

CREATE TABLE test_exists (a int, b text);

-- view

DROP VIEW test_view_exists;

DROP VIEW IF EXISTS test_view_exists;

CREATE VIEW test_view_exists AS select * from test_exists;

DROP VIEW IF EXISTS test_view_exists;

DROP VIEW test_view_exists;

-- index

DROP INDEX test_index_exists;

DROP INDEX IF EXISTS test_index_exists;

CREAT INDEX test_index_exists on test_view_exists(a);

DROP INDEX IF EXISTS test_index_exists;

DROP INDEX test_index_exists;

-- sequence

DROP SEQUENCE test_sequence_exists;

DROP SEQUENCE IF EXISTS test_sequence_exists;

CREATE SEQUENCE test_sequence_exists;

DROP SEQUENCE IF EXISTS test_sequence_exists;

DROP SEQUENCE test_sequence_exists;

-- schema

DROP SCHEMA test_schema_exists;

DROP SCHEMA IF EXISTS test_schema_exists;

CREATE SCHEMA test_schema_exists;

DROP SCHEMA IF EXISTS test_schema_exists;

DROP SCHEMA test_schema_exists;

-- type

DROP TYPE test_type_exists;

DROP TYPE IF EXISTS test__type_exists;

CREATE type test_type_exists as (a int, b text);

DROP TYPE IF EXISTS test__type_exists;

DROP TYPE test_type_exists;

-- domain

DROP DOMAIN test_domain_exists;

DROP DOMAIN IF EXISTS test__domain_exists;

CREATE domain test_domain_exists as int not null check (value > 0);

DROP DOMAIN IF EXISTS test__domain_exists;

DROP DOMAIN test_domain_exists;

-- drop the table

DROP TABLE IF EXISTS test_exists;

DROP TABLE test_exists;

Attachment Content-Type Size
drop-if-exists.patch2 text/plain 33.3 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: drop if exists - first piece
Date: 2005-11-18 23:49:03
Message-ID: 13141.1132357743@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> I will apply the attached patch tomorrow, barring objection. This covers
> drop if exists for the following objects:
> table view index sequence schema type domain conversion

> I have a simple test script as show below, but I am not sure where to
> put it in the regression tests - add a new one maybe?

New test seems reasonable.

A few other minor comments:

* The NOTICEs should probably not carry an ERRCODE; usually you just
want a notice to go out with the default "not an error" SQLSTATE.

* The "Assert(missing_ok)"s are a waste of code space --- if
ereport(ERROR) ever returned, there would be vast swaths of the backend
that fail, so there's no point in asserting it only here. They also
make the reader stop to wonder why they are there, which is probably a
bigger objection.

* It's probably not a good idea to assume that "IF" is a safe name for
a parser symbol --- too much risk of collision with other macros.
I'd suggest "IF_P".

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: drop if exists - first piece
Date: 2005-11-19 17:48:09
Message-ID: 437F6559.1010602@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-patches

Tom Lane wrote:

>New test seems reasonable.
>
>

done.

>A few other minor comments:
>
>* The NOTICEs should probably not carry an ERRCODE; usually you just
>want a notice to go out with the default "not an error" SQLSTATE.
>
>

done.

>* The "Assert(missing_ok)"s are a waste of code space --- if
>ereport(ERROR) ever returned, there would be vast swaths of the backend
>that fail, so there's no point in asserting it only here. They also
>make the reader stop to wonder why they are there, which is probably a
>bigger objection.
>
>

done, but I left one with a modified test to reflect what we are really
testing, i.e. that we didn't fall of the end of a message table.

>* It's probably not a good idea to assume that "IF" is a safe name for
>a parser symbol --- too much risk of collision with other macros.
>I'd suggest "IF_P".
>
>

done.

Thanks for the review.

Committed as above. I will probably do DROP DATABASE IF EXISTS shortly,
but anyone who wants to jump in on others is welcome to.

cheers

andrew