Re: Truncate if exists - Mailing list pgsql-hackers

From Sébastien Lardière
Subject Re: Truncate if exists
Date
Msg-id 50783F5C.5090609@hi-media.com
Whole thread Raw
In response to Re: Truncate if exists  (Simon Riggs <simon@2ndQuadrant.com>)
Responses Re: Truncate if exists
Re: Truncate if exists
List pgsql-hackers
On 10/11/2012 09:22 PM, Simon Riggs wrote:

>>
>> That is a lot more typing and it's not exactly intuitive.  One obvious
>> thing that would help is a function pg_table_exists(text) that would
>> return true or false.  But even with that there's a lot of syntactic
>> sugar in there that is less than ideal: begin/end, dollar-quoting, do.
>>  Whatever becomes of this particular patch, I think we'd make a lot of
>> people really happy if we could find a way to dispense with some of
>> that stuff in simple cases.
>
> Yeh, definitely.
>
> So we just need a function called pg_if_table_exists(table, SQL) which
> wraps a test in a subtransaction.
>
> And you write
>
> SELECT pg_if_table_exists('foo', 'TRUNCATE TABLE foo');
>
> and we can even get rid of all that other DDL crud that's been added....
>
> and we can have pg_if_table_not_exists() also.
>

If we can do something like :

SELECT pg_if_table_exists('bar' , pg_if_table_exists('foo', 'TRUNCATE
TABLE foo, bar, foobar')) ;

or

SELECT pg_if_tables_exists('TRUNCATE TABLE foo, bar, foobar', 'foo',
'bar') ;

I say yes !


--
Sébastien Lardière
PostgreSQL DBA Team Manager
Hi-Media



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: velog + vereport?
Next
From: Andres Freund
Date:
Subject: Re: velog + vereport?