Re: How to prevent modifications in a tree of rows, based on a condition? - Mailing list pgsql-general

From A. Kretschmer
Subject Re: How to prevent modifications in a tree of rows, based on a condition?
Date
Msg-id 20070619111802.GB7819@a-kretschmer.de
Whole thread Raw
In response to How to prevent modifications in a tree of rows, based on a condition?  ("Philippe Lang" <philippe.lang@attiksystem.ch>)
List pgsql-general
am  Tue, dem 19.06.2007, um 12:23:51 +0200 mailte Philippe Lang folgendes:
>
> I'd like to prevent any kind of modification (insert, update, delete) in
> a order (and its lines, and steps) if all the steps in the lines of the
> order are "checked". If that condition is not true, a modification is
> accepted.
>
>
> Does anyone have an idea maybe? The rule system? Thanks for your ideas.

Yes, with RULEs. A simple example to prevent UPDATE for subset rows:

test=# select * from foo;
 id |  t
----+-----
  5 | 1,2
  6 | 2,2
  7 | 3,2
  1 | 1
  1 | 1
  0 | 10
  0 | 10
(7 rows)

test=*# select * from looked ;
 id
----
  1
(1 row)


-- i want to prevent update for all id's listed in table looked


test=*# create rule r1  as on update to foo where old.id in (select id from looked) do instead nothing;
CREATE RULE
test=*# update foo set t = 100 where id=0;
UPDATE 2
test=*# update foo set t = 100 where id=1;
UPDATE 0
test=*# select * from foo;
 id |  t
----+-----
  5 | 1,2
  6 | 2,2
  7 | 3,2
  1 | 1
  1 | 1
  0 | 100
  0 | 100
(7 rows)


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

pgsql-general by date:

Previous
From: "Philippe Lang"
Date:
Subject: How to prevent modifications in a tree of rows, based on a condition?
Next
From: Bill Moran
Date:
Subject: Re: VACUUM ANALYZE extremely slow