Re: a trigger question - Mailing list pgsql-general

From Zhou, Lixin
Subject Re: a trigger question
Date
Msg-id 6EDF654BC7BFE648AB2E734727E7078DAEC77B@illumina24.illumina.com
Whole thread Raw
In response to a trigger question  (pblunat <pblunat@ujf-grenoble.fr>)
List pgsql-general
Thanks Jan!

>> 1) Fire the trigger AFTER INSERT.  BEFORE INSERT won't work.
>> 2) Deferrable does not seem to be important.

>Jan    1) Fire the trigger BEFORE INSERT does work
>Jan    2) If you make the constraint deferred
>Jan    3) And let the trigger return NEW instead of NULL;

This is a really interesting trick!

>> I've tested above, it does work as expected for PK/FKs that are integers.

>Jan    It also works for all other types of keys.

Yes, it should as I pointed out in another email.

I had troubles because I used quot_literal on a new.varchar value within the
PLPGSQL function.  This should cause SQL syntax error (eg: insert into
tbl(a_string) values (''this is a string to be inserted but it will fail to
insert.'') but I got the error message as "referential integrity error"
instead of SQL syntax error.

Thanks again, Jan!  I learnt a lot.

Lixin Zhou

pgsql-general by date:

Previous
From: "Lee Green"
Date:
Subject: Re: [ADMIN] performance issue using DBI
Next
From: "Zhou, Lixin"
Date:
Subject: Re: a trigger question