Re: NEW variable values in actions in rules - Mailing list pgsql-general

From Tom Lane
Subject Re: NEW variable values in actions in rules
Date
Msg-id 6358.1138835696@sss.pgh.pa.us
Whole thread Raw
In response to Re: NEW variable values in actions in rules  ("Ken Winter" <ken@sunward.org>)
Responses Why does an ON SELECT rule have to be named "_RETURN"?  ("Ken Winter" <ken@sunward.org>)
List pgsql-general
"Ken Winter" <ken@sunward.org> writes:
> I have a table "person_h" with a not-null column "effective_date_and_time"
> that defaults to CURRENT_TIMESTAMP.

> I have a view "person" with the following rule defined on it:

> CREATE RULE on_insert AS
>     ON INSERT TO person
>     DO INSTEAD (
>         INSERT INTO person_h (person_id, ...
> effective_date_and_time,             ...)


You need to provide a column default on the view; the one on the
underlying table would only enter into the picture if the "INSERT INTO
person_h" command in the rule omitted specifying effective_date_and_time,
which it does not.

Use ALTER TABLE person ALTER COLUMN ... SET DEFAULT ... to attach a
default to the view.

            regards, tom lane

pgsql-general by date:

Previous
From: "Ken Winter"
Date:
Subject: Re: NEW variable values in actions in rules
Next
From: Bob Pawley
Date:
Subject: Stack Depth