From: | Carl van Tast <vanTast(at)Pivot(dot)at> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: PL/pgSQL loops? |
Date: | 2001-11-28 17:52:49 |
Message-ID: | 9f8a0uccirf0f38ijrdmref7rqeo4tv6vd@4ax.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, 28 Nov 2001 14:49:42 +0000 (UTC), pgsql(at)halfahead(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew G. Hammond | 2001-11-28 21:20:58 | Re: Queue in SQL |
Previous Message | Tom Lane | 2001-11-28 16:49:07 | Re: PL/pgSQL loops? |