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 <al**@meerkatsoft.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
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to
ma*******@postgresql.org)