Re: A VIEW mimicing a TABLE - Mailing list pgsql-general

From Rafal Pietrak
Subject Re: A VIEW mimicing a TABLE
Date
Msg-id 1166092342.27564.99.camel@zorro.isa-geek.com
Whole thread Raw
In response to Re: A VIEW mimicing a TABLE  ("William Leite Araújo" <william.bh@gmail.com>)
List pgsql-general
On Thu, 2006-12-14 at 08:01 -0200, William Leite Araújo wrote:
>
> On 12/13/06, Rafal Pietrak <rafal@zorro.isa-geek.com> wrote:
>         CREATE RULE new_entry_notm AS ON INSERT to logview WHERE
>         new.tm IS NULL
>         DO INSTEAD INSERT (id,info) VALUES (new.id,new.info);
>         CREATE RULE new_entry_notm AS ON INSERT to logview WHERE
>         new.tm IS NULL
>         AND new.id IS NULL DO INSTEAD INSERT (info) VALUES (new.info);
>
>       All can be done with:
>
> CREATE RULE new_entry AS ON INSERT to logview DO INSTEAD INSERT
>    (id,tm,info) VALUES
> (COALESCE(new.id,[default]),COALESCE( new.tm,[default]),COALESCE(new.info,[default]));
>
>
>         Which is overtalkative, but sort of works.

Yes, this one is less overtalkative, but does not solve the problem of
having the default value used ONLY when INSERT *does*not* set the field;
as opposed to the case, when INSERT *sets* the field, but sets it to
NULL.

The above solution would set new.id to [default] in case of: "INSERT
(id) VALUES (null)". Which is not desired.

But in fact, "ALTER TABLE <view_name> ALTER ... SET DEFAULT", suggested
earlier in this thread by Tom Lane does the trick :) Thenx Tom.


-R



pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: iplike.so permission denied
Next
From: "SunWuKung"
Date:
Subject: Re: A VIEW mimicing a TABLE