Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop multiple triggers in a PostgreSQL 9.1 DB

I'm trying to remove multiple triggers but getting a SQL error:

PG::Error: ERROR:  syntax error at or near ";"
LINE 1:     DROP TRIGGER rr_admin_reports;

Here is the sql I'm executing in rails:

sql = <<-SQL
  DROP TRIGGER rr_admin_reports;
  DROP TRIGGER rr_apps;
  DROP TRIGGER rr_attachments;
SQL

Is there a way to easily delete a long list of triggers? Thanks

like image 668
AnApprentice Avatar asked Jan 04 '13 20:01

AnApprentice


People also ask

How do you drop a trigger?

Use the DROP TRIGGER statement to remove a database trigger from the database. The trigger must be in your own schema or you must have the DROP ANY TRIGGER system privilege. To drop a trigger on DATABASE in another user's schema, you must also have the ADMINISTER DATABASE TRIGGER system privilege.

Which command is for removing the trigger?

You can remove triggers using the Remove Physical File Trigger (RMVPFTRG) command, the SQL DROP TRIGGER statement, or System i® Navigator. Use the RMVPFTRG command to remove the association of a file and the trigger program.

How do you drop a trigger in Pgadmin?

To drop a PostgreSQL trigger, we use the DROP TRIGGER statement with the following syntax: DROP TRIGGER [IF EXISTS] trigger-name ON table-name [ CASCADE | RESTRICT ];


1 Answers

DROP TRIGGER rr_admin_reports ON yourTable;

Quote from PostgreSQL documentation:

The DROP TRIGGER statement in PostgreSQL is incompatible with the SQL standard. In the SQL standard, trigger names are not local to tables, so the command is simply DROP TRIGGER name.

http://www.postgresql.org/docs/7.4/static/sql-droptrigger.html

like image 179
Floris Velleman Avatar answered Sep 21 '22 00:09

Floris Velleman