Re: Truncate if exists

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Sébastien Lardière <slardiere(at)hi-media(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Simon Riggs <simon(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, cedric(at)2ndquadrant(dot)fr
Subject: Re: Truncate if exists
Date: 2012-10-09 20:04:40
Message-ID: CA+TgmobtVEpXMbPFZfL2D0yNf4VZ8Vr3uF_tPBuPunJ9P6z=3Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 9, 2012 at 12:28 PM, Sébastien Lardière
<slardiere(at)hi-media(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2012-10-09 20:08:03 Re: Statistics and selectivity estimation for ranges
Previous Message John R Pierce 2012-10-09 19:28:05 Re: pgxs problem...