Re: Conditional delete

From: Qingqing Zhou <zhouqq(at)cs(dot)toronto(dot)edu>
To: Bartosz Jakubiak <bartosz(dot)jakubiak(at)biznespolska(dot)pl>
Subject: Re: Conditional delete
Date: 2005-11-21 23:44:09
Message-ID: Pine.LNX.4.58.0511211842480.12108@eon.cs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 21 Nov 2005, Bartosz Jakubiak wrote:

> Hi.
>
> I'm new with PostgreSQL, but this thing doesn't allow me to sleep:
>
> I wonder if it is possible to execute SQL query which:
> 1. checks out if table exists, and if it is:
> 2. deletes it
> All of it at SQL query level, preferrably in one transaction.
>
> Something like (MSSQL):
> IF EXISTS (SELECT * FROM sysobjects WHERE id =
> object_id(n'properties_branches') AND objectproperty(id, n'isusertable')
> = 1)
> DROP TABLE properties_branches
>
> or (MySQL)
> DROP TABLE IF EXISTS properties_branches;
>

This quite looks like rewrite a script auto generated from SQL Server :-)
Yes, you can do that by querying the system catalog to see if a table
exists (pg_class). However, notice there is possible a race condition
here: if you found one table exists, but when you delete it, it may
already deleted by others.

Regards,
Qingqing

Browse pgsql-general by date

  From Date Subject
Next Message Bob Pawley 2005-11-21 23:53:15 Group By?
Previous Message Qingqing Zhou 2005-11-21 23:38:07 Re: Difference in indexes