check for table existence before dropping

From: "Constantin" <konstant(at)sympatico(dot)ca>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: check for table existence before dropping
Date: 2001-03-12 21:06:24
Message-ID: BAELIEJLNJGGCENBNILCOEAECAAA.konstant@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi

I am trying to to add some SQL code before a CREATE TABLE statement
that checks whether a table exists before dropping it.

This doesnt seem to work:

IF EXISTS( SELECT * FROM pg_class WHERE relname = 'cust' )
THEN
DROP TABLE cust
DROP SEQUENCE cust_cust_id_seq
END IF;

CREATE TABLE cust
(
cust_id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);

Any ideas how to do this with postgresql?
Many thanks :)

Browse pgsql-novice by date

  From Date Subject
Next Message brew 2001-03-12 22:04:44 pg_dump & BLOBs ?
Previous Message Mark, Terry 2001-03-12 20:46:28 pg_dump & BLOBs ?