I'm attempting to drop a trigger that may or may not exist, so am using the "IF EXISTS" clause. Â This works fine for tables, views, functions, domains, and types, but for some reason seems to be ignored for triggers. Â I'd expect to see more about this online if it were a bug, so I'm thinking I may be missing something obvious.
Example: DROP TRIGGER IF EXISTS udf_customer_update_trigger ON customer;
Expected Output: NOTICE:Â Â trigger "udf_customer_update_trigger" does not exist, skipping
Observed Output: ERROR:Â Â relation "udf_customer_update_trigger" does not exist
This has worked the way you're imagining since (I think) 9.4. Before that the "if exists" semantics only applied to the trigger itself, not to the relation.
Alright now I am confused. Other then changing table to table_name I am not seeing where the below changed. In both cases a NOTICE is supposed to be raised.
I will take a look at this at some point. The part that has me confused from the original post is this:
ERROR: relation "udf_customer_update_trigger" does not exist
If the ERROR is because the table does not exist, why not?:
ERROR: relation "customer" does not exist
I assumed this part was a mistake in the post by Michael. I tried this on 9.1.19 and I correctly get the name of the table rather than the name of the trigger. So even in the unlikely event that this was a bug, it's working in the latest 9.1 minor release:
# drop trigger if exists test_trigger on testtable;