Re: Truncate if exists

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Truncate if exists
Date: 2012-10-09 20:18:40
Message-ID: 507486A0.40909@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brar Piening 2012-10-09 20:28:43 Re: Visual Studio 2012 RC
Previous Message Simon Riggs 2012-10-09 20:12:04 Re: Truncate if exists