Connecting Tech Pros Worldwide Forums | Help | Site Map

Conditional delete

Bartosz Jakubiak
Guest
 
Posts: n/a
#1: Nov 23 '05
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;

Anyone?

Thanks. And sorry if it is a stupid question.

--
Bartosz Jakubiak

Bartosz Jakubiak
Guest
 
Posts: n/a
#2: Dec 8 '05

re: Conditional delete


Bartosz Jakubiak napisal(a):[color=blue]
> 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.[/color]

As far as I know it is not possible in SQL.
You have to use one of procedural languages.
For PostgreSQL 7.4 look here:
http://www.postgresql.org/docs/7.4/static/xplang.html

--
Bartosz Jakubiak
Closed Thread