Re: Truncate if exists - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Truncate if exists
Date
Msg-id CA+TgmobtVEpXMbPFZfL2D0yNf4VZ8Vr3uF_tPBuPunJ9P6z=3Q@mail.gmail.com
Whole thread Raw
In response to Re: Truncate if exists  (Sébastien Lardière <slardiere@hi-media.com>)
Responses Re: Truncate if exists  (Josh Berkus <josh@agliodbs.com>)
Re: Truncate if exists  (Sébastien Lardière <slardiere@hi-media.com>)
Re: Truncate if exists  (Greg Stark <stark@mit.edu>)
List pgsql-hackers
On Tue, Oct 9, 2012 at 12:28 PM, Sébastien Lardière
<slardiere@hi-media.com> wrote:
>> For starters, the use-case hasn't been explained to my satisfaction.
>> In what situation is it actually helpful to TRUNCATE a table that's
>> not there yet?  Aren't you going to have to do a CREATE IF NOT EXISTS
>> to keep from failing later in the script?  If so, why not just do that
>> first?
>
> it could be useful to not rollback transactions :
>
>  - if a table is not yet or no more visible, because of search_path
> modification

I don't think I understand the case you are describing here.

>  - if a table was dropped, for any reason

But in this case surely you could use DROP IF EXISTS.

I've been a big proponent of adding "IF EXISTS" support to CREATE
TABLE and ALTER TABLE but I'm having a hard time getting excited about
this one.  I can't imagine that many people would use it, and those
who do can implement it in about 10 lines of PL/pgsql.  The existence
of DO blocks and the fact that PL/pgsql is now installed by default
have made it much more convenient to solve these kinds of problems
using those tools rather than needing dedicated syntax.  That does not
mean that the most frequently used cases shouldn't have dedicated
syntax anyway, for convenience, but I'm doubtful that this falls into
that category.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Detecting libpq connections improperly shared via fork()
Next
From: Alexander Korotkov
Date:
Subject: Re: Statistics and selectivity estimation for ranges