check for table existence before dropping - Mailing list pgsql-novice

From Constantin
Subject check for table existence before dropping
Date
Msg-id BAELIEJLNJGGCENBNILCOEAECAAA.konstant@sympatico.ca
Whole thread Raw
List 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 :)

pgsql-novice by date:

Previous
From: "Dax Duskin"
Date:
Subject: array column problem
Next
From: Michael Jinks
Date:
Subject: Re: Postgres postmaster