Re: [SQL] SQL Script Question

Поиск
Список
Период
Сортировка
От Kovacs Zoltan Sandor
Тема Re: [SQL] SQL Script Question
Дата
Msg-id Pine.LNX.4.05.10002231123340.14711-100000@pc10.radnoti-szeged.sulinet.hu
обсуждение исходный текст
Ответ на SQL Script Question  (Carolyn Wong <carolyn@kss.net.au>)
Список 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 по дате отправления:

Предыдущее
От: Andrzej Mazurkiewicz
Дата:
Сообщение: RE: [SQL] SQL Script Question
Следующее
От: Jerome ALET
Дата:
Сообщение: problem with grant/revoke