This project implements a pl/perl function that blocks 
updates to individual fields of the table.  The function 
is called 'deny_updates'. This function should be set as 
as 'on update' trigger on the table.

This work is sponsored by CashNetUSA (http://cashnetusa.com)

Installation:

cd contrib/deny_updates
make install

Optionally you can run a regression test:
make installcheck.

Run psql to install the function into a database:
psql -f deny_updates.sql $databasename

Make sure your PostgreSQL installation contains pl/perl
support and that pl/perl is installed into the database.

Usage:
Create a new 'on update' trigger on the target table.
 
CREATE TRIGGER deny_test_updates BEFORE UPDATE ON test 
FOR EACH ROW EXECUTE PROCEDURE deny_updates('false', password);

Syntax:
deny_updates([colname1, colname2, ...colnameN], allow_updates)

where colname1, colname2, .. - names of the target relation columns,
allow_updates is a flag, that can be set to 'false', 'f', 'no' or 'n'
to disallow updates of the given columns, or to 'true', 't', 'yes' or 
'y' to disallow updates of all columns except for the given ones.

Examples:

Suppose we have a table called test, defined as: 
CREATE TABLE test(id INTEGER, name VARCHAR, password VARCHAR);

To disallow updates for the password field a trigger should be added using 
the following command:

CREATE TRIGGER deny_test_updates BEFORE UPDATE ON test 
FOR EACH ROW EXECUTE PROCEDURE deny_updates('n', password);

If the goal is to allow updates on id column only then this command can be
implemented:

CREATE TRIGGER deny_test_updates BEFORE UPDATE ON test 
FOR EACH ROW EXECUTE PROCEDURE deny_updates('true', id);

or as an alternative:

CREATE TRIGGER deny_test_updates BEFORE UPDATE ON test 
FOR EACH ROW EXECUTE PROCEDURE deny_updates('false', name, password);

A trigger can be defined with an empty set of arguments. It will allow updates
to every column from the target relation if allow_updates is false, and block
every update to the target relation otherwise.
