Re: column default dependant on another columns value - Mailing list pgsql-sql

From Fernando Hevia
Subject Re: column default dependant on another columns value
Date
Msg-id 007501c8dbc4$9d02f9b0$8f01010a@iptel.com.ar
Whole thread Raw
In response to Re: column default dependant on another columns value  ("Richard Broersma" <richard.broersma@gmail.com>)
Responses Re: column default dependant on another columns value
List pgsql-sql
> -----Mensaje original-----
> De: Richard Broersma [mailto:richard.broersma@gmail.com] 
> 
> It is possible to do this with a trigger or a rule.  A 
> trigger would be more robust.
> 
> > Is this correct? Is there another (better/simpler) way to 
> achieve this?
> 
> Well I might work, but it is a bad practice to get into since 
> what you are trying to do violates the rules of database 
> normalization.
> 
> Wouldn't it be better to calculate the minutes with you query 
> your table?
> 
> SELECT *, seconds / 60 AS minutes
>   FROM yourtable;

Actually I only used this as an example.
The real table is queried lots of times for millions of rows and the server
is showing some high-level user cpu consumption. There are a couple
calculated columns on the table so I am trying to reduce cpu usage by
pre-calculating the more cpu intensive data once on insert. Enhancing the
application is currently not possible.

Anyway, the rule didn't work. Got "an infinite recursion error" when
inserting on the table.
Can't figure out where the recursion is as supposedly the rule kicks in when
the "where minutes is null" condition is satisfied. The DO INSTEAD part runs
an insert were minutes is NOT null so the rule should be ignored. 
Where is the recursion then? I am on postgres 8.2.9.

Thanks for your hindsight Richard. I Will look into the trigger solution.
Still, I'd like to understand this recursion error.

Regards,
Fernando.




pgsql-sql by date:

Previous
From: "Richard Broersma"
Date:
Subject: Re: column default dependant on another columns value
Next
From: Tom Lane
Date:
Subject: Re: column default dependant on another columns value