From: | André Næss <andre(dot)nass(at)student(dot)uib(dot)no> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Conditional rule? |
Date: | 2000-07-28 09:32:46 |
Message-ID: | 00f001bff876$cc57f8d0$74b5f8c2@wkst6 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | André Næss | 2000-07-28 09:40:26 | Re: BLOBs |
Previous Message | Carolyn Lu Wong | 2000-07-28 08:21:02 | Transactions |