By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

Prevent from Deletion

P: n/a
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 ?

Alex

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Alex wrote:
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 ?

Thatt'd be the way.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #2

P: n/a
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)

Nov 11 '05 #3

P: n/a
On Mon, Sep 01, 2003 at 17:50:41 +0200,
Csaba Nagy <na**@ecircle-ag.com> wrote:
I was just wondering if using some rewrite rules is not better:


I think that depends on what you want to have if somebody trys it.
Using do instead nothing will make the attempt look like it succeeded
when it didn't.

---------------------------(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

Nov 11 '05 #4

P: n/a
On Sun, 2003-08-31 at 22:07, Alex wrote:
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 ?


How about revoking DELETE and UPDATE privileges from all users
except the DBA?

--
-----------------------------------------------------------------
Ron Johnson, Jr. ro***********@cox.net
Jefferson, LA USA

"Those who would give up essential Liberty to purchase a little
temporary safety, deserve neither Liberty nor safety." or
something like that
Ben Franklin, maybe
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #5

P: n/a
DBA's never would make the mistake of deleting a record that is a key
part of a design, of course.

;-)

Ron Johnson wrote:
On Sun, 2003-08-31 at 22:07, Alex wrote:

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 ?


How about revoking DELETE and UPDATE privileges from all users
except the DBA?

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.