[open-ils-commits] r9456 - trunk/Open-ILS/src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Sat Apr 26 12:52:53 EDT 2008
Author: miker
Date: 2008-04-26 12:13:13 -0400 (Sat, 26 Apr 2008)
New Revision: 9456
Modified:
trunk/Open-ILS/src/sql/Pg/reporter-schema.sql
Log:
add reporter.materialized_simple_record to the base schema
Modified: trunk/Open-ILS/src/sql/Pg/reporter-schema.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/reporter-schema.sql 2008-04-26 16:12:17 UTC (rev 9455)
+++ trunk/Open-ILS/src/sql/Pg/reporter-schema.sql 2008-04-26 16:13:13 UTC (rev 9456)
@@ -154,6 +154,26 @@
WHERE r.deleted IS FALSE
GROUP BY 1,2,3,4,5,6,8,9;
+CREATE TABLE reporter.materialized_simple_record AS SELECT * FROM reporter.simple_record WHERE 1=0;
+ALTER TABLE reporter.materialized_simple_record ADD PRIMARY KEY (id);
+
+CREATE OR REPLACE FUNCTION reporter.simple_rec_sync () RETURNS TRIGGER AS $$
+BEGIN
+ IF TG_OP IN ('UPDATE','DELETE') THEN
+ DELETE FROM reporter.materialized_simple_record WHERE id = OLD.record;
+ END IF;
+
+ IF TG_OP IN ('INSERT','UPDATE') AND NOT NEW.deleted THEN
+ INSERT INTO reporter.materialized_simple_record SELECT * FROM reporter.simple_record WHERE id = NEW.record;
+ END IF;
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TRIGGER zzz_update_materialized_simple_record_tgr
+ AFTER INSERT OR UPDATE OR DELETE ON metabib.full_rec
+ FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_sync();
+
CREATE OR REPLACE VIEW reporter.demographic AS
SELECT u.id,
u.dob,
More information about the open-ils-commits
mailing list