From: | Csaba Nagy <nagy(at)ecircle-ag(dot)com> |
---|---|
To: | Doug McNaught <doug(at)mcnaught(dot)org> |
Cc: | Alex <alex(at)meerkatsoft(dot)com>, Postgres general mailing list <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Prevent from Deletion |
Date: | 2003-09-01 15:50:41 |
Message-ID: | 1062431442.15712.36.camel@coppola.ecircle.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I was just wondering if using some rewrite rules is not better:
cnagy=> create table test(col1 int4);
CREATE TABLE
cnagy=> insert into test values (0);
INSERT 47709303 1
cnagy=> insert into test values (1);
INSERT 47709304 1
cnagy=> insert into test values (2);
INSERT 47709305 1
cnagy=> insert into test values (3);
INSERT 47709306 1
cnagy=> create or replace rule test_rule as on delete to test where col1
in (1, 2) do instead nothing;
CREATE RULE
cnagy=> select * from test;
col1
------
0
1
2
3
(4 rows)
cnagy=> delete from test;
DELETE 2
cnagy=> select * from test;
col1
------
1
2
(2 rows)
Is there any reason not to use rewrite rules here ? Might be more
performant than triggers...
Cheers,
Csaba.
On Mon, 2003-09-01 at 05:29, Doug McNaught wrote:
> Alex <alex(at)meerkatsoft(dot)com> writes:
>
> > Hi,
> > I have tables that have default records that must not be deleted or
> > modified.
> > Is there an easy way to do this. Like setting a trigger on the Primary
> > key value ?
>
> You could do this--create ON UPDATE and ON DELETE triggers that look
> for distinguishing features of the default records (primary key value
> or whatever) and RAISE ERROR if they match. They'll be executed for
> every UPDATE and DELETE on the table, which may or may not be a
> performance issue for you...
>
> -Doug
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
> joining column's datatypes do not match
From | Date | Subject | |
---|---|---|---|
Next Message | Francois Suter | 2003-09-01 16:24:06 | French translation |
Previous Message | Josh Rovero | 2003-09-01 15:25:21 | More on 7.4b2 vs 7.3.4 performance |