Re: Truncate if exists - Mailing list pgsql-hackers

From Sébastien Lardière
Subject Re: Truncate if exists
Date
Msg-id 50768FBD.4040108@hi-media.com
Whole thread Raw
In response to Re: Truncate if exists  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On 10/09/2012 10:04 PM, Robert Haas wrote:

>>  - 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.

Here's a sample :


begin;
set search_path = foo, public;
create table c ( … ) ;
commit;

begin;
set search_path = bar, public;
create table d ( … );
truncate if exists c;
commit;

>
>>  - if a table was dropped, for any reason
>
> But in this case surely you could use DROP IF EXISTS.

Well, TRUNCATE and DROP TABLE are not the same, I don't see your point ?

>
> 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.
>

I don't think we can ask people to do DO blocks for TRUNCATE, when they
simply use IF EXISTS with DROP TABLE.

Even if TRUNCATE is not a DDL, it's often use as is

--
Sébastien Lardière
PostgreSQL DBA Team Manager
Hi-Media



pgsql-hackers by date:

Previous
From: Dimitri Fontaine
Date:
Subject: Re: replace plugins directory with GUC
Next
From: Sébastien Lardière
Date:
Subject: Re: Truncate if exists