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/

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply via email to