Re: pgsql function doesn't work

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: pgsql function doesn't work
Дата
Msg-id 20030618102030.W33406-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на pgsql function doesn't work  (Erwin Ambrosch <erwin.ambrosch@aon.at>)
Ответы Re: pgsql function doesn't work  ("Mel Jamero" <mel@gmanmi.tv>)
Список pgsql-admin
On Wed, 18 Jun 2003, Erwin Ambrosch wrote:

> Hi,
>
> the function bellow is created successfully, but executing it forces the
> following error message:
>
> WARNING:  Error occurred while executing PL/pgSQL function
> drop_table_if_exists
> WARNING:  line 5 at select into variables
> ERROR:  parser: parse error at or near "$1" at character 34
>
>
> CREATE OR REPLACE FUNCTION drop_table_if_exists(TEXT) RETURNS BOOLEAN AS '
> DECLARE
>    rec RECORD;
> BEGIN
>
>    SELECT INTO rec off_mitarbeiter_id FROM $1;

You can't do this in plpgsql without some form of EXECUTE.

>    IF FOUND THEN
>      EXECUTE ''DROP TABLE'' || '' '' || $1;
>      RETURN true;
>    END IF;
>
>    RETURN false;
>
> END;'
> LANGUAGE 'plpgsql';

However, AFAICS this will error if the table doesn't exist (selecting from
a non-existant table) rather than do nothing which I'm guessing was the
point since otherwise you could do the drop without the function. You
might want to consider querying the system catalogs instead.



В списке pgsql-admin по дате отправления:

Предыдущее
От: Erwin Ambrosch
Дата:
Сообщение: pgsql function doesn't work
Следующее
От: "scott.marlowe"
Дата:
Сообщение: Re: postgreSQL 7.3.3 crashing on server with Itanium