Re: Views and default values - Mailing list pgsql-general

From DaVinci
Subject Re: Views and default values
Date
Msg-id 20010406132639.A611@fangorn.net
Whole thread Raw
In response to Views and default values  (DaVinci <bombadil@wanadoo.es>)
Responses Re: Views and default values
List pgsql-general
On Fri, Apr 06, 2001 at 12:24:09PM +0100, Michael Ansley wrote:
> >>  Data Base:
> >>
> >>      create table foo (
> >>         cod            serial primary key,
> >>         explication    text,
> >>         silly        bool default 't');
> >>
> >>     create view v_foo as
> >>         select * from foo;
> >>
> >>     create rule v_foo_ins as on insert to v_foo do instead
> >>         insert into foo values (
> >>             NEW.cod,
> >>             NEW.explication,
> >>             NEW.silly);
> You should probably have this:
>
> create rule v_foo_ins as on insert to v_foo do instead
>     insert into foo (explication, silly) values (
>         NEW.explication,
>         NEW.silly);
>
> The rule is trying to insert NEW.cod, which is null, into the table.  This
> rule let's the cod field take care of itself.

 That is valid for 'cod' but not for 'silly'. I'd like that if insert value
 is null, then I get default value, but if insert value is not null, this is
 value that is saved.

 Any idea?...

 Thanks.

                                             David

pgsql-general by date:

Previous
From: "Tim Knowles"
Date:
Subject: ...
Next
From: Michael Ansley
Date:
Subject: RE: Views and default values