2013-01-04 3 views
5

Sto cercando di rimuovere più trigger ma ottenere un errore di SQL:Come cadere più trigger in PostgreSQL 9.1 DB

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

Ecco la sql sto eseguendo in rotaie:

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

C'è un modo per cancellare facilmente una lunga lista di trigger? Grazie

risposta

8
DROP TRIGGER rr_admin_reports ON yourTable; 

Citazione dalla documentazione PostgreSQL:

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

+3

C'è un modo per dire GOCCIA TRIGGER IF EXISTS? – AnApprentice

+2

Sì uso: DROP TRIGGER SE ESISTE rr_admin_reports ON yourTable; :) –