From: | Mario Soto Cordones <msotocl(at)gmail(dot)com> |
---|---|
To: | Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Immutable attributes? |
Date: | 2005-04-26 13:49:05 |
Message-ID: | e9b17cde05042606492b4214ab@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi for all , plese a question ,this function can be write in pl/pgsql ???????
thank for all
2005/4/24, Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr>:
> To protect the database from programming errors (there is a team
> working on the project and some beginners may produce bugs), I would
> like to flag some attributes as immutable, meaning non modifiable in
> an UPDATE. (Typical examples are ID or creation time.)
>
> Currently, I use triggers:
>
> CREATE OR REPLACE FUNCTION check_immutable() RETURNS TRIGGER
> AS 'BEGIN
> IF NEW.id != OLD.id OR NEW.created != OLD.created THEN
> RAISE EXCEPTION ''Change not allowed in that table'';
> END IF;
> RETURN NEW;
> END;'
> LANGUAGE PLPGSQL;
>
> CREATE TRIGGER check_immutable
> BEFORE UPDATE ON MyTable
> FOR EACH ROW
> EXECUTE PROCEDURE check_immutable();
>
> It is quite painful, since I need a function (with the list of
> immutable attributes) and a trigger per table. If I INHERITS from a
> table, triggers on the parent table are not called if I update the
> child table.
>
> Is there a better way? I do not find a constraint IMMUTABLE for
> attributes.
>
> PostgreSQL 7.4, switching to 8.0 would be difficult.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
--
cordialmente,
Ing. Mario Soto Cordones
From | Date | Subject | |
---|---|---|---|
Next Message | Stephane Bortzmeyer | 2005-04-26 13:54:51 | Re: Immutable attributes? |
Previous Message | Rich Shepard | 2005-04-26 13:24:43 | Re: Migrating MySQL app to postgres? |