Re: looping on NEW and OLD in a trigger

Поиск
Список
Период
Сортировка
От Dmitriy Igrishin
Тема Re: looping on NEW and OLD in a trigger
Дата
Msg-id AANLkTinbTY==MaNyMCh+-ZhGJAkv51ksMOVXv7OTsRrr@mail.gmail.com
обсуждение исходный текст
Ответ на looping on NEW and OLD in a trigger  ("Michael P. Soulier" <michael_soulier@mitel.com>)
Ответы Re: looping on NEW and OLD in a trigger
Список pgsql-general
Hey Michael,

As of PostgreSQL 9.0 you can do it from PL/pgSQL by
using hstore module
(http://www.postgresql.org/docs/9.0/static/hstore.html)

I wrote an example for you:

CREATE TABLE person(id integer, fname text, lname text, birthday date);

CREATE TRIGGER person_test_trigger BEFORE INSERT
  ON person FOR EACH ROW
  EXECUTE PROCEDURE test_dynamic();

CREATE OR REPLACE FUNCTION test_dynamic()
 RETURNS trigger
 LANGUAGE plpgsql
 AS $func$
DECLARE
  _newRec hstore := hstore(NEW);
  _field text;
BEGIN
  FOR _field IN SELECT * FROM skeys(_newRec) LOOP
    RAISE NOTICE '%', _field;
  END LOOP;

  RETURN NEW;
END;
 $func$;

Regards,
Dmitriy

2010/8/26 Michael P. Soulier <michael_soulier@mitel.com>
Hi,

I'm very new to writing postgres procedures, and I'm trying to loop over
the fields in the NEW and OLD variables available in an after trigger,
and I can't quite get the syntax correct.

Could someone point me at an example?

Thanks,
Mike
--
Michael P. Soulier <michael_soulier@mitel.com>, 613-592-2122 x2522
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: two different posgres t for Rails development?
Следующее
От: Fabrízio de Royes Mello
Дата:
Сообщение: Re: looping on NEW and OLD in a trigger