Re: Firing an event trigger for ADD COLUMN? - Mailing list pgsql-general

From Tanveer Munavar
Subject Re: Firing an event trigger for ADD COLUMN?
Date
Msg-id CAE2XJrO+2aUjyeJwswbQPqhGDWdipYpOSn9kMuDnTi=WwM3w8w@mail.gmail.com
Whole thread Raw
In response to Firing an event trigger for ADD COLUMN?  (Michel Pelletier <pelletier.michel@gmail.com>)
List pgsql-general

> Is this asymmetry a bug?  I realize these event trigger functions are typically written in C, but I'd like to keep this idea contained to a plpgsql function and cover as many reversible changes as I can.

This is the expected behavior since pg_event_trigger_ddl_commands function does not return object_name unlike the pg_event_trigger_dropped_objects. 


Logging the statement through log_statement=ddl or higher is the only way I see to capture the details of alter statement. 

On Tue, May 12, 2020 at 4:57 AM Michel Pelletier <pelletier.michel@gmail.com> wrote:
I'm writing a script that "reverses" ddl operations in an "up" script by capturing event triggers and generating a "down" script for reverting.  I've got it working great for tables, indexes, etc, but it seems ADD COLUMN doesn't sent an event, here's the code i'm using, pasted straight from the documentation:


And here's the results I get, I get an event for dropping a column, but not adding one:

postgres=# create table foo (bar int);
NOTICE:  CREATE TABLE created object: table public public.foo
CREATE TABLE
postgres=# alter table foo add column baz int;
NOTICE:  ALTER TABLE created object: table public public.foo
ALTER TABLE
postgres=# alter table foo drop column bar;
NOTICE:  ALTER TABLE dropped object: table column public.<NULL> public.foo.bar
NOTICE:  ALTER TABLE created object: table public public.foo
ALTER TABLE
postgres=#

Is this asymmetry a bug?  I realize these event trigger functions are typically written in C, but I'd like to keep this idea contained to a plpgsql function and cover as many reversible changes as I can.

Thank you,

-Michel


--
Thanks,
Mohamed Tanveer
988-061-3565
www.linkedin.com/in/tanveermunavar

pgsql-general by date:

Previous
From: Michel Pelletier
Date:
Subject: Firing an event trigger for ADD COLUMN?
Next
From: Alvaro Herrera
Date:
Subject: Re: Firing an event trigger for ADD COLUMN?