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

Поиск
Список
Период
Сортировка
От Paul Jungwirth
Тема Re: Trigger (or something similar) on table rename?
Дата
Msg-id 261abb38-4c77-becf-fc1e-8bd7eee1445b@illuminatedcomputing.com
обсуждение исходный текст
Ответ на Trigger (or something similar) on table rename?  (Ken Tanzer <ken.tanzer@gmail.com>)
Список 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@illuminatedcomputing.com


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Trigger (or something similar) on table rename?
Следующее
От: Don Seiler
Дата:
Сообщение: vacuumdb --all Parallel Feature Request