0

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

  • 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? – Igor Romanchenko May 21 '13 at 13:31
  • yes just do nothing in the trigger or ignore it completely – Ser Yoga May 21 '13 at 13:32
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.

  • 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 ... – Ser Yoga May 21 '13 at 13:45
  • Hm. Maybe. I havent tested my ansver. – Igor Romanchenko May 21 '13 at 13:47
  • 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. – Igor Romanchenko May 21 '13 at 13:48
  • i think its to overelaborate :( – Ser Yoga May 21 '13 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.