pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: André Næss <andre.nass@student.uib.no>
To: pgsql-sql@postgresql.org
Subject: Re: Conditional rule?
Date: Fri, 28 Jul 2000 11:32:46 +0200
Message-ID: <00f001bff876$cc57f8d0$74b5f8c2@wkst6> (raw)
References: <200007272216.AAA28690@hot.jw.home>

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




view thread (11+ messages)  latest in thread

Message-ID: <00f001bff876$cc57f8d0$74b5f8c2@wkst6>
Permalink:  ../00f001bff876$cc57f8d0$74b5f8c2@wkst6/
Also on:    postgresql.org/message-id/00f001bff876$cc57f8d0$74b5f8c2@wkst6

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andre.nass@student.uib.no
  Subject: Re: Conditional rule?
  In-Reply-To: <00f001bff876$cc57f8d0$74b5f8c2@wkst6>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox