Search Postgresql Archives

Re: Conditional delete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux