Re: The Contrib Roundup (long) - Mailing list pgsql-hackers

From Michael Fuhr
Subject Re: The Contrib Roundup (long)
Date
Msg-id 20050608144607.GB71845@winnie.fuhr.org
Whole thread Raw
In response to The Contrib Roundup (long)  (Josh Berkus <josh@agliodbs.com>)
List pgsql-hackers
On Tue, Jun 07, 2005 at 02:53:32PM -0300, Josh Berkus wrote:
>
> noupdate: this is a cool example of a simple C trigger and would
> be lovely to have in a doc somewhere.  However, its
> functionality is easily replicated through a simple PL/pgSQL
> trigger so it seems unnecessary as a contrib module.  Author
> unattributed.

Does noupdate even work correctly?  The README is pretty thin so
maybe I've misunderstood something.  First of all, the example fails
due to a case problem:
 CREATE TABLE TEST ( COL1 INT, COL2 INT, COL3 INT );  CREATE TRIGGER BT BEFORE UPDATE ON TEST FOR EACH ROW
EXECUTEPROCEDURE          noup ('COL1');  INSERT INTO TEST VALUES (10,20,30); UPDATE TEST SET COL1 = 5; ERROR:  noup:
thereis no attribute COL1 in relation test
 

If we fix the case problem then this particular example works:
 DROP TRIGGER BT ON TEST;  CREATE TRIGGER BT BEFORE UPDATE ON TEST FOR EACH ROW         EXECUTE PROCEDURE          noup
('col1'); UPDATE TEST SET COL1 = 5; WARNING:  col1: update not allowed UPDATE 0
 

But the trigger won't allow updates on other columns either:
 UPDATE TEST SET COL2 = 15; WARNING:  col1: update not allowed UPDATE 0

...unless we *do* change COL1 to NULL:
 UPDATE TEST SET COL1 = NULL, COL2 = 15; UPDATE 1

The code rejects the update if the new value for the designated
column (col1 in this case) is not NULL, rather than checking if
its value has changed.  Is that the intended behavior?

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: adding new pages bulky way
Next
From: Josh Berkus
Date:
Subject: Re: The Contrib Roundup (long)