Re: Truncate if exists - Mailing list pgsql-hackers

From Josh Berkus
Subject Re: Truncate if exists
Date
Msg-id 507486A0.40909@agliodbs.com
Whole thread Raw
In response to Re: Truncate if exists  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Truncate if exists  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Robert,

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

On the other hand, it's useful to consistently have "IF EXISTS" syntax
for the majority of utility commands.  It's confusing to users that they
can do "DROP TABLE IF EXISTS" but not "TRUNCATE IF EXISTS", even if the
latter is less useful than the former.  So that's one reason to support
this.

The second is for making deployment scripts idempotent.  For example,
say you have script A which creates table "josh", and script B which
needs table "josh" to be empty, if present.  Since the two scripts are
tied to different database features, and you don't know which one will
be deployed first, it's useful to have TRUNCATE IF EXISTS.  Yes, you can
solve that problem with DO, but why make users go to the extra effort?

Is it *as* useful as other IF EXISTS?  No.  Is it replaceable with a DO
$$ statement?  Yes.  Is that a reason to block a fairly trivial patch
which makes things 0.1% easier for users?  No.

Not if the patch itself is broken, that's another story.

-- 
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com



pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Truncate if exists
Next
From: Brar Piening
Date:
Subject: Re: Visual Studio 2012 RC