From: | Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> |
---|---|
To: | PostgreSQL Developers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | ERROR action extension for rules? |
Date: | 2004-04-20 14:10:32 |
Message-ID: | Pine.LNX.4.58.0404201550250.6454@sablons.cri.ensmp.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Dear hackers,
I'm trying to use some RULE as simple and maybe slower TRIGGER, so as to
make it impossible for a row to be modified once a boolean is set to lock
it.
CREATE TABLE foo(data TEXT, locked BOOLEAN NOT NULL DEFAULT FALSE);
This cannot be done with a CHECK constraint as it is not a restriction
about the state of the tuple, but instead to its changes.
What I could do is to skip the attempt with a NOTHING action:
CREATE RULE PasTouche AS ON UPDATE TO foo
WHERE old.locked=TRUE
DO INSTEAD NOTHING;
but as a result the attempt is not reported to the transaction, which
goes on. I really want to generate an error so as to abort the
current transaction. After various attempts, I did the following:
CREATE TABLE Boom(ok BOOLEAN CHECK(ok=TRUE));
CREATE RULE PasTouche AS ON UPDATE TO foo
WHERE old.locked=TRUE
DO INSTEAD INSERT INTO Boom(ok) VALUES(FALSE);
It works, as an error is raised because the attempt fails on the check.
Other solutions could be thought off with the same result, and that
would basically use the same kind of trick...
However I thing that this would look much better to write simply:
CREATE RULE PasTouche AS ON UPDATE TO foo
WHERE old.locked=TRUE
DO INSTEAD ERROR;
I think this simple new rule action could be added to pg.
I'm planning to do it, if there is no opposition.
Any comments on this proposed new rule action?
Or did I missed something obvious with rules?
Have a nice day,
--
Fabien Coelho - coelho(at)cri(dot)ensmp(dot)fr
From | Date | Subject | |
---|---|---|---|
Next Message | Fabien COELHO | 2004-04-20 14:25:41 | Re: CSV patch applied |
Previous Message | Andrew Dunstan | 2004-04-20 14:03:51 | Re: COPY CSV keywords |