Tuesday, July 1, 2008

Re: [SQL] column default dependant on another columns value

On Tue, Jul 1, 2008 at 1:12 PM, Fernando Hevia <fhevia@ip-tel.com.ar> wrote:

> Given a table with columns seconds and minutes, how can I have minutes be
> computed automatically at the insert statement?

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;


--
Regards,
Richard Broersma Jr.

Visit the Los Angles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

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

No comments: