From: | Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com> |
---|---|
To: | William Leite Araújo <william(dot)bh(at)gmail(dot)com> |
Cc: | PostgreSQL general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: A VIEW mimicing a TABLE |
Date: | 2006-12-14 10:32:22 |
Message-ID: | 1166092342.27564.99.camel@zorro.isa-geek.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 2006-12-14 at 08:01 -0200, William Leite Araújo wrote:
>
> On 12/13/06, Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | SunWuKung | 2006-12-14 10:45:12 | Re: A VIEW mimicing a TABLE |
Previous Message | Richard Huxton | 2006-12-14 10:08:23 | Re: iplike.so permission denied |