Re: v9.1, DROP TRIGGER IF EXISTS behaving oddly

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: "Williamson, Michael" <Michael(dot)Williamson(at)tamucc(dot)edu>, "david(dot)rowley(at)2ndquadrant(dot)com" <david(dot)rowley(at)2ndquadrant(dot)com>
Cc: "tgl(at)sss(dot)pgh(dot)pa(dot)us" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: v9.1, DROP TRIGGER IF EXISTS behaving oddly
Date: 2016-01-14 22:26:41
Message-ID: 569820A1.5030807@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 01/14/2016 01:47 PM, Williamson, Michael wrote:
> Please excuse my mistake.
>
> We were dropping a view that had the trigger on it beforehand, then in
> trying to re-build the entire schema had scripts that attempted to drop
> trigger if they existed before re-creating the view and triggers. I
> over-sanitized the example I posted and made it unclear.
>
> I did some more testing and DROP TRIGGER IF EXISTS indeed works as
> expected if the table/view is there and the trigger is not there.
>
> As a follow-up, it would be nice if "IF EXISTS" could apply to either
> the trigger or the relation it is applied to, as I don't think a
> trigger can't exist without a relation to apply it to.

That is the part Tom and David where trying to explain to me and I was
not getting, the behavior has changed.

Some testing revealed this:

test=# select version();
version

----------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 9.0.20 on i686-pc-linux-gnu, compiled by GCC gcc (SUSE
Linux) 4.8.1 20130909 [gcc-4_8-branch revision 202388], 32-bit
(1 row)

test=# drop trigger if exists test_trg on test_tbl;
ERROR: relation "test_tbl" does not exist

test=# select version();
version

-----------------------------------------------------------------------------------------------------------------------------
PostgreSQL 9.4.5 on i686-pc-linux-gnu, compiled by gcc (SUSE Linux)
4.8.3 20140627 [gcc-4_8-branch revision 212064], 32-bit
(1 row)

test=# drop trigger if exists test_trg on test_tbl;
NOTICE: relation "test_tbl" does not exist, skipping
DROP TRIGGER

In either case though IF EXISTS did the right thing, so I am wondering
if upgrading to a more recent version of 9.1 will help you.

>
> Michael
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2016-01-14 23:41:54 PgDay LFNW April 23rd & 24th (can you speak?)
Previous Message Joshua D. Drake 2016-01-14 21:48:24 Re: WIP: CoC V6