Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: column defa...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 3556 of 3799
Post > Topic >>

Re: column default dependant on another columns value

by fhevia@[EMAIL PROTECTED] ("Fernando Hevia") Jul 2, 2008 at 10:52 AM

> -----Mensaje original-----
> De: pgsql-sql-owner@[EMAIL PROTECTED]
 
> [mailto:pgsql-sql-owner@[EMAIL PROTECTED]
 En nombre de Tom Lane
> Enviado el: Martes, 01 de Julio de 2008 19:24
> Para: Fernando Hevia
> CC: 'Richard Broersma'; pgsql-sql@[EMAIL PROTECTED]
> Asunto: Re: [SQL] column default dependant on another columns value 
> 
> "Fernando Hevia" <fhevia@[EMAIL PROTECTED]
> writes:
> > Anyway, the rule didn't work. Got "an infinite recursion 
> error" when 
> > inserting on the table.
> > Can't figure out where the recursion is
> 
> You didn't show us the rule, but I imagine that you think the 
> WHERE clause is applied while expanding the rule.  It's not, 
> it can only suppress rows at run-time; and what you've got is 
> infinite macro expansion recursion.
> 

I see. In that case rules do not serve this particular purpose. 
It seems a trigger should be the tool for solving this.

Just to confirm, this is my test case:

create table table1 (
   column1 text,
   seconds integer,
   minutes integer );

CREATE RULE "my_rule" AS ON
INSERT TO table1
WHERE minutes is null
DO INSTEAD
INSERT INTO table1 (column1, seconds, minutes) VALUES(new.column1,
new.seconds, new.seconds/60);

insert into table1 values ('a', 60);         --- Here the rule should kick
in right?
insert into table1 values ('b', 120, NULL);  --- Rule should kick in too.
insert into table1 values ('c', 180, 3);     --- the rule should not apply
since minutes is not null.

Of course, all three of them throw the recursion error.


-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 5 Posts in Topic:
column default dependant on another columns value
fhevia@[EMAIL PROTECTED]   2008-07-01 17:12:30 
Re: column default dependant on another columns value
richard.broersma@[EMAIL P  2008-07-01 13:44:46 
Re: column default dependant on another columns value
fhevia@[EMAIL PROTECTED]   2008-07-01 18:51:27 
Re: column default dependant on another columns value
tgl@[EMAIL PROTECTED] (T  2008-07-01 18:24:24 
Re: column default dependant on another columns value
fhevia@[EMAIL PROTECTED]   2008-07-02 10:52:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:49:57 CST 2008.