Re: column default dependant on another columns value
От | Fernando Hevia |
---|---|
Тема | Re: column default dependant on another columns value |
Дата | |
Msg-id | 007501c8dbc4$9d02f9b0$8f01010a@iptel.com.ar обсуждение исходный текст |
Ответ на | Re: column default dependant on another columns value ("Richard Broersma" <richard.broersma@gmail.com>) |
Ответы |
Re: column default dependant on another columns value
|
Список | 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 по дате отправления: