From: Carl van Tast <vanTast@Pivot.at>
To: pgsql-sql@postgresql.org
Subject: Re: PL/pgSQL loops?
Date: Wed, 28 Nov 2001 18:52:49 +0100
Message-ID: <9f8a0uccirf0f38ijrdmref7rqeo4tv6vd@4ax.com> (raw)
References: <200111281540250450.0093EFC2@mail.halfahead.dk>
On Wed, 28 Nov 2001 14:49:42 +0000 (UTC), pgsql@halfahead.dk ("Johnny
Jørgensen") wrote:
> << order_loop >>
> FOR cur_order IN SELECT * FROM ordre WHERE person_id =3D p_id AND status =
>=3D 1 AND id !=3D o_id
> LOOP
> RAISE NOTICE ''outer: %'',cur_order.id;
>
> << item_loop >>
> FOR cur_item IN SELECT * FROM item WHERE order_id =3D cur_order_id
> LOOP
> RAISE NOTICE ''inner: %'',cur_item.id;
>
> UPDATE item SET ordre_id =3D o_id WHERE id =3D cur_item.id;
>
> END LOOP;
>
> UPDATE ordre SET status =3D 0 WHERE id =3D cur_order.id;
>
> END LOOP;
Don't know much about LOOPs. But wouldn't this do want you want?
UPDATE item
SET ordre_id = o_id
FROM ordre
WHERE ordre.id = item.ordre_id
AND ordre.person_id = p_id AND ordre.status = 1 AND ordre.id != o_id
UPDATE ordre
SET status = 0
WHERE person_id = p_id AND status = 1 AND id != o_id
Kind regards,
Carl van Tast
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: vanTast@Pivot.at
Subject: Re: PL/pgSQL loops?
In-Reply-To: <9f8a0uccirf0f38ijrdmref7rqeo4tv6vd@4ax.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox