Search Postgresql Archives

Re: Refreshing functional index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux