Skip to content

Commit

Permalink
#801 add latest mat view and trigger function
Browse files Browse the repository at this point in the history
  • Loading branch information
chmnata committed Feb 15, 2024
1 parent 4d78ee0 commit 9aeac92
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions gis/centreline/sql/create_matview_centreline_latest.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE MATERIALIZED VIEW gis_core.centreline_latest AS
SELECT *
FROM gis_core.centreline
WHERE version_date = (SELECT MAX(version_date) FROM gis_core.centreline);

CREATE TRIGGER refresh_trigger
AFTER INSERT OR UPDATE OR DELETE
ON gis_core.centreline
FOR EACH STATEMENT
EXECUTE PROCEDURE gis_core.centreline_latest_trigger();

CREATE INDEX gis_core_centreline_latest_geom
ON gis_core.centreline_latest USING gist(geom);

ALTER MATERIALIZED VIEW gis_core.centreline_latest OWNER TO gis_admins;

GRANT SELECT ON gis_core.centreline_latest TO bdit_humans;

COMMENT ON MATERIALIZED VIEW gis_core.centreline_latest IS 'Materialized view containing the latest version of centreline, derived from gis_core.centreline.'
18 changes: 18 additions & 0 deletions gis/centreline/sql/create_trigger_centreline_latest.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE OR REPLACE FUNCTION gis_core.centreline_latest_trigger()
RETURNS trigger
LANGUAGE 'plpgsql'
COST 100
VOLATILE NOT LEAKPROOF SECURITY DEFINER
AS $BODY$
BEGIN

REFRESH MATERIALIZED VIEW gis_core.centreline_latest;
RETURN NULL;

END;
$BODY$;

ALTER FUNCTION gis_core.centreline_latest_trigger() OWNER TO gis_admins;

COMMENT ON FUNCTION gis_core.centreline_latest_trigger() IS 'Trigger fuction that refreshes the centreline_latest mat view after an update.';

0 comments on commit 9aeac92

Please sign in to comment.