Re: Prevent from Deletion

Поиск
Список
Период
Сортировка
От Csaba Nagy
Тема Re: Prevent from Deletion
Дата
Msg-id 1062431442.15712.36.camel@coppola.ecircle.de
обсуждение исходный текст
Ответ на Re: Prevent from Deletion  (Doug McNaught <doug@mcnaught.org>)
Ответы Re: Prevent from Deletion
Список 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@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



В списке pgsql-general по дате отправления:

Предыдущее
От: Josh Rovero
Дата:
Сообщение: More on 7.4b2 vs 7.3.4 performance
Следующее
От: Francois Suter
Дата:
Сообщение: French translation