Re: PL/pgSQL loops?

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: PL/pgSQL loops?
Дата
Msg-id 20011128081825.J32047-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на PL/pgSQL loops?  ("Johnny Jørgensen" <pgsql@halfahead.dk>)
Список pgsql-sql
I'm not really sure of what's going on, and am uncertain
if this is a transcription error or not.  In addition
table schema would be helpful for us to try the function. :)

In my machine with test tables I get,
NOTICE:  Error occurred while executing PL/pgSQL function cleanup_order
NOTICE:  line 13 at for over select rows
ERROR:  Attribute 'cur_order_id' not found

I assume this is because of the use of cur_order_id rather than
cur_order.id in the inner loop definition.

On Wed, 28 Nov 2001, [ISO-8859-1] "Johnny J�rgensen" wrote:

> I have a problem with the following function:
>
> CREATE FUNCTION cleanup_order(integer,integer)
> RETURNS boolean
> AS '
>  DECLARE
>   p_id  ALIAS FOR $1;
>   o_id  ALIAS FOR $2;
>   cur_order record;
>   cur_item record;
>  BEGIN
>   << order_loop >>
>   FOR cur_order IN SELECT * FROM ordre WHERE person_id = p_id AND status = 1 AND id != o_id
>   LOOP
>    RAISE NOTICE ''outer: %'',cur_order.id;
>
>    << item_loop >>
>    FOR cur_item IN SELECT * FROM item WHERE order_id = cur_order_id
>    LOOP
>     RAISE NOTICE ''inner: %'',cur_item.id;
>
>     UPDATE item SET ordre_id = o_id WHERE id = cur_item.id;
>
>    END LOOP;
>
>    UPDATE ordre SET status = 0 WHERE id = cur_order.id;
>
>   END LOOP;
>   RETURN TRUE;
>  END;
> '
> LANGUAGE 'plpgsql';




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

Предыдущее
От: "James Orr"
Дата:
Сообщение: Re: View question
Следующее
От: Tom Lane
Дата:
Сообщение: Re: PL/pgSQL loops?