-
Notifications
You must be signed in to change notification settings - Fork 28
/
pg_ivm--1.0.sql
66 lines (49 loc) · 1.49 KB
/
pg_ivm--1.0.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- catalog
CREATE SCHEMA __pg_ivm__;
CREATE TABLE __pg_ivm__.pg_ivm_immv(
immvrelid regclass NOT NULL,
viewdef text NOT NULL,
CONSTRAINT pg_ivm_immv_pkey PRIMARY KEY (immvrelid)
);
ALTER TABLE __pg_ivm__.pg_ivm_immv SET SCHEMA pg_catalog;
--CREATE UNIQUE INDEX ON pg_catalog.pg_ivm_immv USING btree (immvrelid);
SELECT pg_catalog.pg_extension_config_dump('pg_catalog.pg_ivm_immv', '');
-- functions
CREATE FUNCTION create_immv(text, text)
RETURNS bigint
STRICT
AS 'MODULE_PATHNAME', 'create_immv'
LANGUAGE C;
-- trigger functions
CREATE FUNCTION "IVM_immediate_before"()
RETURNS trigger
AS 'MODULE_PATHNAME', 'IVM_immediate_before'
LANGUAGE C;
CREATE FUNCTION "IVM_immediate_maintenance"()
RETURNS trigger
AS 'MODULE_PATHNAME', 'IVM_immediate_maintenance'
LANGUAGE C;
CREATE FUNCTION "IVM_prevent_immv_change"()
RETURNS trigger
AS 'MODULE_PATHNAME', 'IVM_prevent_immv_change'
LANGUAGE C;
/*
* DDL trigger that removes entry from pg_ivm_immv
*/
CREATE FUNCTION pg_ivm_sql_drop_trigger_func()
RETURNS event_trigger AS $$
DECLARE
pg_class_oid OID;
relids REGCLASS[];
BEGIN
pg_class_oid = 'pg_catalog.pg_class'::regclass;
/* Find relids to remove */
DELETE FROM pg_catalog.pg_ivm_immv
USING pg_catalog.pg_event_trigger_dropped_objects() AS events
WHERE immvrelid = events.objid AND
events.classid = pg_class_oid AND events.objsubid = 0;
END
$$ LANGUAGE plpgsql;
CREATE EVENT TRIGGER pg_ivm_sql_drop_trigger
ON sql_drop
EXECUTE PROCEDURE pg_catalog.pg_ivm_sql_drop_trigger_func();