Re: Truncate if exists - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Truncate if exists
Date
Msg-id CAM-w4HOwYmv-035+uR05ud1DuUotse4_weMmGgkHft4bDVwmng@mail.gmail.com
Whole thread Raw
In response to Re: Truncate if exists  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Truncate if exists  (Josh Berkus <josh@agliodbs.com>)
List pgsql-hackers
On Tue, Oct 9, 2012 at 9:04 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> 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

The reason CREATE IF NOT EXISTS and DROP IF EXISTS are so useful is
because they're shortcuts for ensuring some specific state is always
true. Regardless of whether the table existed before, now it does or
doesn't as desired. (The concern about create was in fact specifically
that it wouldn't guarantee that the same table definition would exist
afterwards)

The same is not true of TRUNCATE IF EXISTS. In that case after the
command has run either the table exists and is empty or it doesn't
exist and still needs to be created.

I take it the intended use is something like
TRUNCATE IF EXISTS foo;
CREATE IF NOT EXISTS foo...

So perhaps what we really need is a CREATE OR TRUNCATE foo(...), but
just plain TRUNCATE IF EXISTS doesn't seem to make sense.




-- 
greg



pgsql-hackers by date:

Previous
From: Christopher Browne
Date:
Subject: Re: Truncate if exists
Next
From: Josh Berkus
Date:
Subject: Re: Truncate if exists