Re: column default dependant on another columns value

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
To: "Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: column default dependant on another columns value
Date: 2008-07-01 20:44:46
Message-ID: 396486430807011344t4e305cd8n510b1e79496c8cdd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Jul 1, 2008 at 1:12 PM, Fernando Hevia <fhevia(at)ip-tel(dot)com(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Fernando Hevia 2008-07-01 21:51:27 Re: column default dependant on another columns value
Previous Message Fernando Hevia 2008-07-01 20:12:30 column default dependant on another columns value