Re: Refreshing functional index - Mailing list pgsql-general

From Grzegorz Tańczyk
Subject Re: Refreshing functional index
Date
Msg-id 11816457.568391346438363182.JavaMail.root@Polzone
Whole thread Raw
In response to Re: Refreshing functional index  ("David Johnston" <polobo@yahoo.com>)
List pgsql-general
Hello,

W dniu 2012-08-31 20:25, David Johnston pisze:
> The question becomes how do you update the "item id" on the "groups"
> table when you add new records to "items".

I have a trigger on items table:

CREATE TRIGGER items_insert
   BEFORE INSERT
   ON items
   FOR EACH ROW
   EXECUTE PROCEDURE items_oninsert();

CREATE OR REPLACE FUNCTION items_oninsert()
   RETURNS trigger AS
$BODY$
BEGIN
   UPDATE groups SET last_item = NEW.id WHERE id=NEW.group AND
(last_item IS NULL OR last_item<NEW.id);
    RETURN NEW;
END;
$BODY$
   LANGUAGE 'plpgsql' VOLATILE;

Thanks!

--
Regards,
   Grzegorz



pgsql-general by date:

Previous
From: Alan Hodgson
Date:
Subject: Re: Tigger after delete with plpgsql
Next
From: fellipeh
Date:
Subject: Re: Tigger after delete with plpgsql