blob: a4716153dfac06b7f202829a9e408a068acc7276 (
plain)
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
|
CREATE EXTENSION test_ddl_deparse;
CREATE OR REPLACE FUNCTION test_ddl_deparse()
RETURNS event_trigger LANGUAGE plpgsql AS
$$
DECLARE
r record;
r2 record;
cmdtype text;
objtype text;
tag text;
BEGIN
FOR r IN SELECT * FROM pg_event_trigger_ddl_commands()
LOOP
-- verify that tags match
tag = public.get_command_tag(r.command);
IF tag <> r.command_tag THEN
RAISE NOTICE 'tag % doesn''t match %', tag, r.command_tag;
END IF;
-- log the operation
cmdtype = public.get_command_type(r.command);
IF cmdtype <> 'grant' THEN
RAISE NOTICE 'DDL test: type %, tag %', cmdtype, tag;
ELSE
RAISE NOTICE 'DDL test: type %, object type %', cmdtype, r.object_type;
END IF;
-- if alter table, log more
IF cmdtype = 'alter table' THEN
FOR r2 IN SELECT *
FROM public.get_altertable_subcmdinfo(r.command)
LOOP
RAISE NOTICE ' subcommand: type % desc %', r2.cmdtype, r2.objdesc;
END LOOP;
END IF;
END LOOP;
END;
$$;
CREATE EVENT TRIGGER test_ddl_deparse
ON ddl_command_end EXECUTE PROCEDURE test_ddl_deparse();
|