Re: Trigger (or something similar) on table rename?

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Trigger (or something similar) on table rename?
Date: 2018-02-15 19:08:43
Message-ID: 261abb38-4c77-becf-fc1e-8bd7eee1445b@illuminatedcomputing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 02/15/2018 10:52 AM, Ken Tanzer wrote:
> Hi.  I'm wondering about possibilities for taking action when a table is
> renamed.

I've looked into this a bit. Here is what I understand:

Since 9.3 Postgres has had "event triggers" which can run code on DDL
events
(https://www.postgresql.org/docs/current/static/event-triggers.html)
There are events like `ddl_command_start` and tags like `ALTER TABLE`.
So you could write a trigger that fires `ON ddl_command_start WHEN TAG
IN ('ALTER TABLE')`.

Unfortunately I don't think you can get the old/new table name from
inside the trigger function. If you need that, you might take a look at
this extension which adds some custom event triggers with ways of
getting that information:

https://github.com/CartoDB/pg_schema_triggers

If you are really adventurous you could even look at using the
ProcessUtility hook directly to do what you need.

I'm looking forward to seeing what others say here because I'd like to
know more myself!

Good luck!

--
Paul ~{:-)
pj(at)illuminatedcomputing(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Don Seiler 2018-02-15 19:30:20 vacuumdb --all Parallel Feature Request
Previous Message Tom Lane 2018-02-15 19:01:53 Re: Trigger (or something similar) on table rename?