From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Josh Berkus <josh(at)agliodbs(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: The Contrib Roundup (long) |
Date: | 2005-06-08 14:46:07 |
Message-ID: | 20050608144607.GB71845@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
EXECUTE PROCEDURE
noup ('COL1');
INSERT INTO TEST VALUES (10,20,30);
UPDATE TEST SET COL1 = 5;
ERROR: noup: there is 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/
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2005-06-08 15:45:42 | Re: The Contrib Roundup (long) |
Previous Message | Hannu Krosing | 2005-06-08 14:30:44 | Re: [PATCHES] regexp_replace |