Re: Truncate if exists

From: Greg Stark <stark(at)mit(dot)edu>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Sébastien Lardière <slardiere(at)hi-media(dot)com>, 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-12 22:49:05
Message-ID: CAM-w4HOwYmv-035+uR05ud1DuUotse4_weMmGgkHft4bDVwmng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 9, 2012 at 9:04 PM, Robert Haas <robertmhaas(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2012-10-12 22:56:14 Re: Truncate if exists
Previous Message Christopher Browne 2012-10-12 22:30:51 Re: Truncate if exists