How to get the name of a modified table in a Postgres event trigger?

in the database postgres, there is a table base1that is the base table for presentation view1.

if a column in base1is created, dropped, or renamed, I would like to recreate the view view1using a ddl trigger.

create event trigger base1_views
   on ddl_command_end
   when tag in( 'ALTER TABLE' )
   execute procedure base1_views_fn();

create function base1_views_fn() returns void as $$
declare
  buf varchar;
begin
  -- is table being altered = 'base'?
  -- add, drop or renaming a column?
  buf = 'drop view view1';
  execute buf;
  buf = 'create view view1 as select * from base1 where ...';
  execute buf;
end;
$$ language 'plpgsql';

inside the function base1_views_fn(), how do we get the table name and change the columns?

+4
source share
2 answers

same problem as here: How to get SQL text from a Postgres event trigger

for now, wait for more features to be added to EVENT TRIGGER in future releases

+2

, plpgsql :

http://www.postgresql.org/docs/9.3/static/plpgsql-trigger.html#PLPGSQL-EVENT-TRIGGER-EXAMPLE

, , - "". , :

TG_EVENT
Data type text; a string representing the event the trigger is fired for.

TG_TAG
Data type text; variable that contains the command tag for which the trigger is fired.

, , , . , . , , , , TG_TABLE_NAME?

+1

Source: https://habr.com/ru/post/1539156/


All Articles