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

From Richard Broersma
Subject Re: column default dependant on another columns value
Date
Msg-id 396486430807011344t4e305cd8n510b1e79496c8cdd@mail.gmail.com
Whole thread Raw
In response to column default dependant on another columns value  ("Fernando Hevia" <fhevia@ip-tel.com.ar>)
Responses Re: column default dependant on another columns value
List pgsql-sql
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


pgsql-sql by date:

Previous
From: "Fernando Hevia"
Date:
Subject: column default dependant on another columns value
Next
From: "Fernando Hevia"
Date:
Subject: Re: column default dependant on another columns value