Re: [SQL] SQL Script Question - Mailing list pgsql-sql

From Kovacs Zoltan Sandor
Subject Re: [SQL] SQL Script Question
Date
Msg-id Pine.LNX.4.05.10002231123340.14711-100000@pc10.radnoti-szeged.sulinet.hu
Whole thread Raw
In response to SQL Script Question  (Carolyn Wong <carolyn@kss.net.au>)
List pgsql-sql
> if <table exists>
>     drop table xxx;
> 
> How can i write this 'if' condition? Or are there any other ways to
> check this??

This SELECT tells you whether a table exists or not:

SELECT tablename FROM pg_tables WHERE tablename='searched_table_name';

With this you can check the condition. Then you may write a PLPGSQL
function which can decide if there was any found table with
searched_table_name or not, see the PLPGSQL example in the src/plpgsql 
library.

Then you may call an SQL function (you should write it first) from the
PLPGSQL function which drops table. As I know, you cannot drop a table
inside a PLPGSQL function (only if you call an external SQL function).

I hope this helps. If not, ask for details.

Regards,
Zoltan



pgsql-sql by date:

Previous
From: Andrzej Mazurkiewicz
Date:
Subject: RE: [SQL] SQL Script Question
Next
From: Jerome ALET
Date:
Subject: problem with grant/revoke