Re: plpgsql function Syntax

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: plpgsql function Syntax
Дата
Msg-id 20040901192016.N90367@megazone.bigpanda.com
обсуждение исходный текст
Ответ на plpgsql function Syntax  (derrick@grifflink.com)
Список pgsql-novice
On Wed, 1 Sep 2004 derrick@grifflink.com wrote:

> Is it possible to get a select statement to work like this with a for loop?
>
> CREATE FUNCTION public.search(int4)
>   RETURNS SETOF search1 AS
> '
> DECLARE
> category alias for $1;
> newrows search1%rowtype;
> rec RECORD;
> SQLCommand varchar;
>
> BEGIN
>     IF (category = 0) THEN
>         SQLCommand := 'SELECT * FROM table';
>     ELSE
>         SQLCommand := 'SELECT idnumber FROM table';
>     END IF;
>
>     FOR rec IN SQLCommand
>         LOOP
>             ...blah...
>             ...blah...
>     END LOOP;
>
> Basically I want to create the SELECT statement dynamically and then use
> that select statement in subsequent querries later in the function.  Will
> this syntax work or should I try to use a VIEW?

You should be able to use FOR rec IN EXECUTE SQLCommand LOOP to execute
the string and loop over the results I think.


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

Предыдущее
От: derrick@grifflink.com
Дата:
Сообщение: plpgsql function Syntax
Следующее
От: derrick@grifflink.com
Дата:
Сообщение: Re: plpgsql function Syntax