Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxxxxxxx




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux