Re: Alter column - Mailing list pgsql-novice

From Tom Lane
Subject Re: Alter column
Date
Msg-id 28414.1155557878@sss.pgh.pa.us
Whole thread Raw
In response to Alter column  (Mike Ellsworth <nhrcommu@rochester.rr.com>)
List pgsql-novice
Mike Ellsworth <nhrcommu@rochester.rr.com> writes:
> Is there a way to convert data type `datetime` into an integer
> (unix_timestamp) while doing ALTER COLUMN `column_name` TYPE int4
> USING CAST(`column_name` as integer) ...... something like this?

Something involving extract(epoch) would do that ... but why do you
want to?  If the column is really timestamps then you are almost always
best off to declare it as timestamps.  When you have a client that wants
a numeric version, they can do the extract(epoch) bit when they select
the data (or you can make a view that does so, if the client code is
too brain-dead to manage it for itself).  The normal rule of good
database design is that the database should have as much knowledge
as possible about what it's storing, not as little as possible.

            regards, tom lane

pgsql-novice by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Alter column
Next
From: Mike Ellsworth
Date:
Subject: Re: Alter column