Re: Conditional rule?
От | André Næss |
---|---|
Тема | Re: Conditional rule? |
Дата | |
Msg-id | 00f001bff876$cc57f8d0$74b5f8c2@wkst6 обсуждение исходный текст |
Ответ на | Re: Conditional rule? (JanWieck@t-online.de (Jan Wieck)) |
Список | pgsql-sql |
----- Original Message ----- > No. The rule > > CREATE RULE newsrule AS ON INSERT TO news > WHERE new.publishtime NOTNULL DO > INSERT INTO news_unpublished VALUES (new.id); > > should do the job perfectly. Maybe you want to have the > following rules too: The following happens: rules=# insert into news (title, time) values('Hei', now()); ERROR: <unnamed> referential integrity violation - key referenced from news_unpublished not found in news Seems the data is inserted into news_unpublished first, thereby violating the constraint I have defined for the news_id field (see below). After removing the constraint a second problem arose; the id created for news (serial) was 4, while the id inserted into news_unpublished was 3. So far a trigger procedure seems to be the best solution. > CREATE RULE newsrule4 AS ON DELETE TO news > WHERE old.publishtime NOTNULL DO > DELETE FROM news_unpublished WHERE news_unpublished.id = old.id; This is also achieved by the following right? (id is the primary key for news): create table news_unpublished ( news_id int references news on delete cascade ); André Næss
В списке pgsql-sql по дате отправления: