Cannot drop trigger getting error in PostgreSQL

2.3k Views Asked by At

I am learning PostgreSQL after python. I follow tutorialspoint.com website.

There is no problem until i create a trigger and it works like a charm..

But when I tried to delete (i.e., drop) the trigger, i get the following error.

DROP TRIGGER example_trigger;
ERROR:  syntax error at or near ";"
LINE 1: DROP TRIGGER example_trigger;
                                    ^

I am not sure why do I get this error. Help me please. Is it common or am I going wrong?

2

There are 2 best solutions below

0
AudioBubble On BEST ANSWER

As documented in the manual, the correct syntax is:

drop trigger example_trigger on table_name;
0
Super Kai - Kazuya Ito On

I created my_t trigger on test table as shown below:

CREATE TRIGGER my_t AFTER UPDATE ON test
FOR EACH ROW EXECUTE FUNCTION my_func();

Then, I tried to drop my_t trigger as shown below:

DROP TRIGGER my_t;

But, I got the same error below:

ERROR: syntax error at or near ";"
LINE 1: DROP TRIGGER my_t;

So, I set test table with ON as shown below, then I could drop my_t trigger without error. *The doc explains how to drop a trigger in detail:

               -- ↓ ↓ ↓ ↓
DROP TRIGGER my_t ON test;

In addition, the SQL below with RESTRICT is exactly same as the SQL above:

DROP TRIGGER my_t ON test RESTRICT;