Re: Truncate if exists - Mailing list pgsql-hackers

From Josh Berkus
Subject Re: Truncate if exists
Date
Msg-id 5078924D.9020106@agliodbs.com
Whole thread Raw
In response to Re: Truncate if exists  (Dimitri Fontaine <dimitri@2ndQuadrant.fr>)
List pgsql-hackers
>> where CONDITION has several possible forms:
>>   i) {IF|UNLESS} ( SQL expression returning T/F )
>>   ii) {IF|UNLESS} {EXISTS|NOT EXISTS}
>> {TABLE|SCHEMA|COLUMN|FUNCTION|...} object_name
> 
> Now we're talking about T-SQL? Sorry, I suppose you didn't mean to lead
> us that way, but I couldn't resist comparing. Soon enough you want a
> full programming language there.

Well, embedding such a thing into plpgsql wouldn't be a bad thing.  It's
a lot less hard on the DevOps person to request that they write a DO
statement if the DO statement is one line:

DO $$
BEGIN
TRUNCATE TABLE foo IF EXISTS foo;
END;$$;

Come to think of it, I've *often* wished for the perl-ish "do x if y"
syntax for plpgsql, and not just for DDL.

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



pgsql-hackers by date:

Previous
From: Dimitri Fontaine
Date:
Subject: Re: Truncate if exists
Next
From: Christopher Browne
Date:
Subject: Re: Truncate if exists