Re: foreach in sql functions

Поиск
Список
Период
Сортировка
Искать
От
Richard Huxton
Тема
Re: foreach in sql functions
Дата
Msg-id
200210030934.05374.dev@archonet.com
Ответ на
Список
Дерево обсуждения
Re: foreach in sql functions "Oleg Lebedev" <oleg.lebedev@waterford.org>
On Wednesday 02 Oct 2002 11:16 pm, Zac Hillier wrote:
>
> Is it possible to write sql functions with a foreach style loop?
>
> CREATE FUNCTION crt_bsk_dtl(integer) RETURNS integer AS '
> SELECT PrdKey FROM Prd WHERE Sts < 999;
> foreach(Prd.PrdKey){
>     INSERT INTO BskDtl (BskKey, PrdKey) VALUES ($1, Prd.PrdKey);
> }
> SELECT 1;
> ' LANGUAGE SQL

Other people are suggesting plpgsql, but for this case you can use SQL:

INSERT INTO BskDtl (BskKey,PrdKey) SELECT $1,PrdKey FROM Prd WHERE Sts < 999;

I realise in a more general case you might want to manipulate data as you loop 
though.

- Richard Huxton
В списке pgsql-general по дате отправления
От: Patrick Fiche
Дата:
Сообщение: Re: foreach in sql functions
От: Jean-Christian Imbeault
Дата:
FAQ