Re: Conditional test

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Rick Dayao <rickd(at)open-works(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Conditional test
Date: 2002-01-03 17:04:38
Message-ID: 200201031704.g03H4cR15169@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Rick Dayao wrote:
> I am trying to solve this problem:
>
> If a table exists, drop the table, otherwise continue processing.
>
> For example, if table X exists, then drop table X. How would I do
> this in SQL? I can query the pg_tables table to see which tables
> exist, but I'm looking for an If-Else construct in SQL.

You can drop the table and ignore the error if returned. We will have
CREATE OR REPLACE in 7.2, but no conditional DROP.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2002-01-03 17:06:09 Re: Retrieving information from System Tables
Previous Message Jason Earl 2002-01-03 16:20:17 Re: change null to 0 in SQL script