Search Postgresql Archives

Re: A VIEW mimicing a TABLE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2006-12-14 at 08:01 -0200, William Leite Araújo wrote:
> 
> On 12/13/06, Rafal Pietrak <rafal@xxxxxxxxxxxxxxxxxx> 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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux