Re: How to make a non-removable row in a table? - Mailing list pgsql-general

From Капралов Александр
Subject Re: How to make a non-removable row in a table?
Date
Msg-id CAJqqVEXWVWpBamihiWnXRmbBurHOj-C3w8KLy-XPM-_Uvjb4ug@mail.gmail.com
Whole thread Raw
In response to Re: How to make a non-removable row in a table?  (Thomas Markus <t.markus@proventis.net>)
Responses Re: How to make a non-removable row in a table?  (Thomas Markus <t.markus@proventis.net>)
List pgsql-general
I found a simple solution, but i don't know how to add raises an exception here.

create rule protect_profile_id0_update as  on update to web.profile
where old.id = 0  do instead nothing;
create rule protect_profile_id0_delete as  on delete to web.profile
where old.id = 0  do instead nothing;

2011/12/19 Thomas Markus <t.markus@proventis.net>:
> Hi,
>
> create a delete trigger that raises an exception
>
> Thomas
>
>
> Am 19.12.2011 07:43, schrieb Капралов Александр:
>
>> Hi all.
>>
>> How to make a non-removable row in a table?
>>
>> In my case, I should not accidentally delete a row with id = 0.
>>
>> CREATE TABLE profile (
>>
>>     id integer NOT NULL,
>>
>>     name character varying(265) NOT NULL
>>
>> );
>>
>> CREATE SEQUENCE profile_id_seq
>>     START WITH 1
>>     INCREMENT BY 1
>>     NO MAXVALUE
>>     NO MINVALUE
>>     CACHE 1;
>>
>> ALTER TABLE profile ALTER COLUMN id SET DEFAULT
>> nextval('profile_id_seq'::regclass);
>>
>> ALTER TABLE ONLY profile ADD CONSTRAINT profile_pkey PRIMARY KEY (id);
>>
>> INSERT INTO profile VALUES (0,'non-removable Profile');
>>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: David Johnston
Date:
Subject: Re: ignore duplicate key while using COPY?
Next
From: Thomas Markus
Date:
Subject: Re: How to make a non-removable row in a table?