Re: Calling function (table_name, schema_name) within event trigger

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Calling function (table_name, schema_name) within event trigger
Date: 2015-12-28 11:23:16
Message-ID: 20151228112316.GA4875@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Susan Hurst <susan(dot)hurst(at)brookhurstdata(dot)com> wrote:

> hmmmm...well, Tom, at least you saved me a lot of frustration with
> trying to get this to work :-) For the time being, I'll just follow up
> DDL activity with a procedure that compares diffs between
> information_schema and the history tables. If and when pl/pgsql offers
> the capture of DDL activity on the fly, I can just move my code to an
> event trigger.

This works in 9.5:

CREATE FUNCTION test_event_trigger_for_create()
RETURNS event_trigger LANGUAGE plpgsql AS $$
DECLARE
obj record;
BEGIN
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
LOOP
RAISE NOTICE '% created object: %',
tg_tag,
obj.object_identity;
END LOOP;
END
$$;
CREATE EVENT TRIGGER test_event_trigger_for_create
ON ddl_command_end
EXECUTE PROCEDURE test_event_trigger_for_create();

Demo:

test=*# create table foo (i int);
NOTICE: CREATE TABLE created object: public.foo
CREATE TABLE
test=*#

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2015-12-28 12:51:41 Re: Options for complex materialized views sharing most of the same logic?
Previous Message Hiroyuki Sato 2015-12-28 02:00:58 Re: grep -f keyword data query