Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In a pgsql event trigger on tag ALTER TABLE, I wish to know which table is being altered.

The pg variables do not cover this, nor do the variables exposed by GET STACKED DIAGNOSTICS.

With variables available, is there any way within the trigger function itself to see the text of the SQL command responsible for initiating the function.

for example, if

ALTER TABLE base1 ADD COLUMN col1 int;

were responsible for calling the event trigger, is there any way within the event trigger to see then ALTER TABLE base1 ADD COLUMN col1 int text itself?

share|improve this question
3  
SELECT current_query(). But it'll only show the top level query, which isn't necessarily what fired the event trigger - say, if you did an ALTER TABLE with a PL/PgSQL function. Event triggers will be extended to add much more information about the command, but are currently very limited in 9.3/9.4 . –  Craig Ringer May 6 '14 at 7:21
    
@CraigRinger - thanks. looking forward to extensions! –  cc young May 6 '14 at 7:34
1  
If you write an event trigger in C, you have also the parse tree of the command. postgresql.org/docs/9.3/static/event-trigger-interface.html Surely not the best approach to rely on that, but its something until this feature is extended. –  pozs May 6 '14 at 7:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.