Re: How to create trigger if it does not exist - Mailing list pgsql-general

From mustachebrownbear
Subject Re: How to create trigger if it does not exist
Date
Msg-id 1360944248465-5745434.post@n5.nabble.com
Whole thread Raw
In response to Re: How to create trigger if it does not exist  ("Andrus" <kobruleht2@hot.ee>)
List pgsql-general
Hi Guys,
Using CASCADE can be a bit dangerous as there might be other tables,
functions, views etc. that will be dropped but they are not meant to be.

Try this:

DO
$$
BEGIN
IF NOT EXISTS(SELECT *
                     FROM information_schema.triggers
                     WHERE event_object_table = 'tablename'
                     AND trigger_name = 'triggername'
                     )
                    THEN
                                 <Insert your create trigger syntx here>;


    END IF ;

END;
$$






--
View this message in context:
http://postgresql.1045698.n5.nabble.com/How-to-create-trigger-if-it-does-not-exist-tp1882226p5745434.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

pgsql-general by date:

Previous
From: "René Romero Benavides"
Date:
Subject: Re: PG9.2.3. Query hanging: SELECT count(*) FROM pg_catalog.pg_class...
Next
From: Cochise Ruhulessin
Date:
Subject: Re: Immutable functions, Exceptions and the Query Optimizer