Re: PL/pgSQL loops?

Поиск
Список
Период
Сортировка
Искать
От
Stephan Szabo
Тема
Re: PL/pgSQL loops?
Дата
Msg-id
20011128194857.G37828-100000@megazone23.bigpanda.com
Ответ на
Re: PL/pgSQL loops? (Johnny J\xF8rgensen)
Список
Дерево обсуждения
Re: PL/pgSQL loops? Carl van Tast <vanTast@Pivot.at>

Something like the below seemed to make it work for me under
7.2b3:
CREATE FUNCTION cleanup_order(integer,integer)RETURNS booleanAS ' -- [INT order_id] cleanup_order ( INT person_id, INT order_id )-- purpose: when a session is interrupted, the order is left open, when the next session is initiated,--                 transfer the items to a new order, and mark the older order void ( so we can tell if f.x. people abort--                an order in the payment phase, e.g. indicating they dont like our payment options )
 DECLARE  p_id  ALIAS FOR $1;  o_id  ALIAS FOR $2;   ord record;   itm record;
 BEGIN
  -- loop through existing open orders from this person, excluding the first, being the active one  FOR ord IN SELECT id FROM ordre WHERE person_id = p_id AND status = 1 AND id != o_id  LOOP       -- loop through items linked to the currently looped order       FOR itm IN SELECT id FROM item WHERE ordre_id = ord.id       LOOP
            -- relink item to latest order            UPDATE item SET ordre_id = o_id WHERE id = itm.id;
       END LOOP;
       -- mark old orders as void       UPDATE ordre SET status = 0 WHERE id = ord.id;
  END LOOP;
  RETURN true;
 END;'LANGUAGE 'plpgsql';



В списке pgsql-sql по дате отправления
От: Haywood J'Bleauxmie
Дата:
Сообщение: distinct() vs distinct on ()
От: Tom Lane
Дата:
FAQ