1

Hello i have a problem with a Trigger

i have 2 tables:

  • t_mandant
  • t_user_has_mandant

when i delete a row in t_user_has_mandant i call a trigger beforeDeleteUserMandant() but i need a possibility to ignore the trigger call when i delete a mandant from t_mandant

because t_user_has_mandant has a foreign key on t_mandant which is on delete cascade.

im using postgres 8.4

3
  • So, you want to change the logic of a trigger on t_user_has_mandant if the delete was caused by CASCADE FK from t_mandant? Commented May 21, 2013 at 13:31
  • yes just do nothing in the trigger or ignore it completely Commented May 21, 2013 at 13:32
  • @SerYoga, did you ever find a good solution to this problem? Commented Jun 7, 2020 at 23:01

1 Answer 1

1

Read this page of the manual.

Using the variable

TG_TABLE_NAME

Data type name; the name of the table that caused the trigger invocation.

You can determine if the DELETE was from t_user_has_mandant or t_mandant.

Sign up to request clarification or add additional context in comments.

4 Comments

i tried it: RAISE NOTICE 'table_name: %', TG_TABLE_NAME; the result was NOTICE: table_name: t_user_has_mandant but my sql query was delete from t_mandant where id_mandant = 555 ...
Hm. Maybe. I havent tested my ansver.
The other (but a bit ugly) way is to query pg_stat_activity view to get the text of current query and search for table names in it.
i think its to overelaborate :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.