Unix Technical Forum

Re: thw rewriter and default values, again

This is a discussion on Re: thw rewriter and default values, again within the pgsql Hackers forums, part of the PostgreSQL category; --> Jaime Casanova <systemguards@gmail.com> writes: > create rule ins_rule as on insert to v_foo do instead > insert into foo(col1, ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 05:06 AM
Tom Lane
 
Posts: n/a
Default Re: thw rewriter and default values, again

Jaime Casanova <systemguards@gmail.com> writes:
> create rule ins_rule as on insert to v_foo do instead
> insert into foo(col1, col2) values (new.col1, new.col2);


> insert into v_foo(col2) values (1);


> this give an error like:
> psql:f:/views.sql:13: ERROR: null value in column "col1" violates
> not-null constraint


That's not a bug, and "fixing" it isn't acceptable.

The correct solution to the problem you are looking at is
to attach default expressions to the view itself. Adding

alter table v_foo alter col1 set default nextval('public.foo_col1_seq');

to your example makes it work as you wish.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 05:06 AM
Jaime Casanova
 
Posts: n/a
Default Re: thw rewriter and default values, again

On 5/28/05, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Jaime Casanova <systemguards@gmail.com> writes:
> > create rule ins_rule as on insert to v_foo do instead
> > insert into foo(col1, col2) values (new.col1, new.col2);

>
> > insert into v_foo(col2) values (1);

>
> > this give an error like:
> > psql:f:/views.sql:13: ERROR: null value in column "col1" violates
> > not-null constraint

>
> That's not a bug, and "fixing" it isn't acceptable.
>
> The correct solution to the problem you are looking at is
> to attach default expressions to the view itself. Adding
>
> alter table v_foo alter col1 set default nextval('public.foo_col1_seq');
>
> to your example makes it work as you wish.
>

I know you're right, but -when dealing with updateable views- doing
that implies to add a lot of time altering views when base table
change, and of course we maybe don't want all views get that values.

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 05:14 AM
Richard Huxton
 
Posts: n/a
Default Re: thw rewriter and default values, again

Jaime Casanova wrote:
> I know you're right, but -when dealing with updateable views- doing
> that implies to add a lot of time altering views when base table
> change, and of course we maybe don't want all views get that values.


Sorry for the late posting on this thread.

Might there be any way to have something like ...SET DEFAULT
pg_same_as('public','foo','col1').

Hmm - you'd need pg_same_as_int/text/etc. depending on the return-type -
still not ideal.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 05:14 AM
Jaime Casanova
 
Posts: n/a
Default Re: thw rewriter and default values, again

On 6/6/05, Richard Huxton <dev@archonet.com> wrote:
> Jaime Casanova wrote:
> > I know you're right, but -when dealing with updateable views- doing
> > that implies to add a lot of time altering views when base table
> > change, and of course we maybe don't want all views get that values.

>
> Sorry for the late posting on this thread.
>
> Might there be any way to have something like ...SET DEFAULT
> pg_same_as('public','foo','col1').
>
> Hmm - you'd need pg_same_as_int/text/etc. depending on the return-type -
> still not ideal.
>

Actually, i try to do that but i need the function to be polymorphic
and because polymorphic functions needs to receive at least one
polymorphic argument that teach about the return type of the function
i can't go ahead with this idea.

About the code i talk earler in this thread i solve the problem with
the update to serial columns.

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com