Re: event trigger should provide more details - Mailing list pgsql-general

From Erik Wienhold
Subject Re: event trigger should provide more details
Date
Msg-id 694730690.528476.1685487804385@office.mailbox.org
Whole thread Raw
In response to Re: event trigger should provide more details  (Lian Jiang <jiangok2006@gmail.com>)
List pgsql-general
> On 31/05/2023 00:28 CEST Lian Jiang <jiangok2006@gmail.com> wrote:
>
> The info useful for me is command_tag, object_type, object_identity.
> classid, objid is not useful since object_identity is more explicit.
> objsubid is not useful because I don't need comment
> (https://www.postgresql.org/message-id/Pine.LNX.4.33.0212091822050.15095-100000@leary.csoft.net)
> information for schema change.

You need objsubid to identify the column in pg_attribute to get its type, not
just to get the comment from pg_description as the linked thread says.

> Besides table name, I still need:
> * which columns are added and their types.
> * which columns have type change, the old and new types.
> * which columns are dropped.
>
> Will command field provide this info? I don't have an example and decoding it
> needs C code (https://www.postgresql.org/message-id/20190712222343.GA26924%40alvherre.pgsql).
> If I cannot get such info from pg_event_trigger_ddl_commands, I may need to
> maintain schema snapshots myself and diff the old and new snapshots upon an
> alter table/view event. Which way should I go? Thanks a lot.

Right off the bat, I would combine it with a ddl_command_start event trigger to
record the necessary info (current columns and their types) in a temp table.
Query this table in the ddl_command_end event trigger to figure out which
columns have changes.  This can be done entirely in plpgsql without using the
command column.

--
Erik



pgsql-general by date:

Previous
From: Lian Jiang
Date:
Subject: Re: event trigger should provide more details
Next
From: Randy Needham
Date:
Subject: Re: Having issue with SSL.