Re: Conditional delete - Mailing list pgsql-general

From Qingqing Zhou
Subject Re: Conditional delete
Date
Msg-id Pine.LNX.4.58.0511211842480.12108@eon.cs
Whole thread Raw
List 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



pgsql-general by date:

Previous
From: "Qingqing Zhou"
Date:
Subject: Re: Difference in indexes
Next
From: Bob Pawley
Date:
Subject: Group By?