Thread: [Q] TRIGGER-RULE

[Q] TRIGGER-RULE

From
Max Buvry
Date:
I begin with Postgres and have a little problem to
define integrity constraint. I check the mailing-
lists archive but I don't find the answer exactly.

For example, I consider the following database :

    CD(id_cd, author, title, id_owner)
    OWNER(id_owner, name, tel)
    BORROW(id_cd, id_owner)

At each insertion in BORROW, I want to check that
the two values id_cd and id_owner already exist
in CD and OWNER. Otherwise the insertion has not
to be executed.

First, is it better to use RULE or TRIGGER for that ?

I try to use RULE as following :

CREATE RULE r1 AS
ON INSERT TO borrow
WHERE new.id_cd NOT IN (SELECT id_cd FROM cd)
DO INSTEAD NOTHING;

When I execute this query, no problem. But when I
attempt to insert a new record in BORROW, an error
occurs : "ERROR : ExecEvalExpr:unknown expression type 108".
Do tou know what happened exactly ?

In advance, thank you for your response.

MB