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