From: Erik Wienhold <ewie@ewie.name>
To: Lian Jiang <jiangok2006@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: event trigger should provide more details
Date: Wed, 31 May 2023 01:03:24 +0200 (CEST)
Message-ID: <694730690.528476.1685487804385@office.mailbox.org> (raw)
In-Reply-To: <CA+aY8X4nKOfoRgMBebGAsw7YU3o9r-0EkqkcXe5xoyDJP6qZrg@mail.gmail.com>
References: <CA+aY8X7=FZmg0V-+5HN+FBRJRgZ4j0TFqknJucetd3uaGnKJMA@mail.gmail.com>
<1154091521.527097.1685482957284@office.mailbox.org>
<CA+aY8X4nKOfoRgMBebGAsw7YU3o9r-0EkqkcXe5xoyDJP6qZrg@mail.gmail.com>
> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ewie@ewie.name, jiangok2006@gmail.com
Subject: Re: event trigger should provide more details
In-Reply-To: <694730690.528476.1685487804385@office.mailbox.org>
References: <CA+aY8X7=FZmg0V-+5HN+FBRJRgZ4j0TFqknJucetd3uaGnKJMA@mail.gmail.com> <1154091521.527097.1685482957284@office.mailbox.org> <CA+aY8X4nKOfoRgMBebGAsw7YU3o9r-0EkqkcXe5xoyDJP6qZrg@mail.gmail.com> <694730690.528476.1685487804385@office.mailbox.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox