Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Conditional delete

Question posted by: Bartosz Jakubiak (Guest) on November 23rd, 2005 02:04 AM
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's Avatar
Bartosz Jakubiak
Guest
n/a Posts
December 8th, 2005
08:45 AM
#2

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

 
Not the answer you were looking for? Post your question . . .
189,872 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors