3

I have two environments, each of them have different trigger's name and I want to use the same script on both envs to drop a trigger I have...

The problem is, when I do as follows:

variable := 'trigger_name';

DROP TRIGGER variable ON my_table;

it tries to DROP a trigger named 'variable' not 'trigger_name' as I expected... How can I do such thing?

Thank you in advance! -B.J.

1 Answer 1

3

You must use dynamic SQL with EXECUTE. You're already using PL/PgSQL, so just:

variable := 'trigger_name';

EXECUTE format('DROP TRIGGER %I ON my_table', variable);
Sign up to request clarification or add additional context in comments.

Comments

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.