Another INSTEAD OF TRIGGER question

Started by stanabout 6 years ago5 messagesgeneral
Jump to latest
#1stan
stanb@panix.com

Still working on updateable views.

Wish list item, a way to see the entire query that caused the trigger to
fire.

Now on to something i hope I can get. Can I see what the verb that caused
the trigger to fire is? IE UPDATE, INSERT, DELETE?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

#2stan
stanb@panix.com
In reply to: stan (#1)
Re: Another INSTEAD OF TRIGGER question

On Sun, Mar 08, 2020 at 10:29:09AM -0400, stan wrote:

Still working on updateable views.

Wish list item, a way to see the entire query that caused the trigger to
fire.

Now on to something i hope I can get. Can I see what the verb that caused
the trigger to fire is? IE UPDATE, INSERT, DELETE?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

OH, what was I thinking, that is controled by the trigger.

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

#3Rob Sargent
robjsargent@gmail.com
In reply to: stan (#2)
Re: Another INSTEAD OF TRIGGER question

On Mar 8, 2020, at 8:31 AM, stan <stanb@panix.com> wrote:

On Sun, Mar 08, 2020 at 10:29:09AM -0400, stan wrote:

Still working on updateable views.

Wish list item, a way to see the entire query that caused the trigger to
fire.

Now on to something i hope I can get. Can I see what the verb that caused
the trigger to fire is? IE UPDATE, INSERT, DELETE?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

OH, what was I thinking, that is controled by the trigger.

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

Or that is what controls which trigger is fired.

Show quoted text
#4Sándor Daku
daku.sandor@gmail.com
In reply to: stan (#2)
Re: Another INSTEAD OF TRIGGER question

On Sun, 8 Mar 2020 at 15:31, stan <stanb@panix.com> wrote:

On Sun, Mar 08, 2020 at 10:29:09AM -0400, stan wrote:

Still working on updateable views.

Wish list item, a way to see the entire query that caused the trigger to
fire.

Now on to something i hope I can get. Can I see what the verb that caused
the trigger to fire is? IE UPDATE, INSERT, DELETE?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

OH, what was I thinking, that is controled by the trigger.

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

Hi,

Still, you can access that information in the TG_OP variable available in
trigger functions because you can define triggers firing on
multiple operation types.
For instance this is an example from the Postgres documentation:

CREATE TRIGGER emp_audit
INSTEAD OF INSERT OR UPDATE OR DELETE ON emp_view
FOR EACH ROW EXECUTE FUNCTION update_emp_view();

Regards,
Sándor

#5stan
stanb@panix.com
In reply to: stan (#1)
Re: Another INSTEAD OF TRIGGER question

On Sun, Mar 08, 2020 at 10:07:24PM +0100, S??ndor Daku wrote:

On Sun, 8 Mar 2020 at 21:26, stan <stanb@panix.com> wrote:

On Sun, Mar 08, 2020 at 03:56:56PM +0100, S??ndor Daku wrote:

On Sun, 8 Mar 2020 at 15:31, stan <stanb@panix.com> wrote:

On Sun, Mar 08, 2020 at 10:29:09AM -0400, stan wrote:

Still working on updateable views.

Wish list item, a way to see the entire query that caused the

trigger to

fire.

Now on to something i hope I can get. Can I see what the verb that

caused

the trigger to fire is? IE UPDATE, INSERT, DELETE?

--
"They that would give up essential liberty for temporary safety

deserve

neither liberty nor safety."
-- Benjamin Franklin

OH, what was I thinking, that is controled by the trigger.

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

Hi,

Still, you can access that information in the TG_OP variable available in
trigger functions because you can define triggers firing on
multiple operation types.
For instance this is an example from the Postgres documentation:

CREATE TRIGGER emp_audit
INSTEAD OF INSERT OR UPDATE OR DELETE ON emp_view
FOR EACH ROW EXECUTE FUNCTION update_emp_view();

Thaks for the info.

Could yoou clarify how to acces this variable:

This does not work:

elog( NOTICE, "For OP $_TD->{TG_OP}" )

But this does work

elog( NOTICE, "On Table $_TD->{table_name}" );
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

Hi,

Sorry I didn't know you are using something different than plpgsql.
You can check the actual syntax for your language(plperl I guess) here:

https://www.postgresql.org/docs/11/server-programming.html

Look for the "Trigger functions" section below the corresponding language.

Yes, it is not there, which explains why I did not see it.

I can execute an SQL queryy from within plperl, do you think that will get
this value?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin