Re: convert column of integer type to time type?

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Carol Cheung <cacheung(at)consumercontact(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: convert column of integer type to time type?
Date: 2007-06-27 16:22:45
Message-ID: 0EF72AB1-0FD2-4251-891A-C0F2DA38DA40@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


On Jun 27, 2007, at 10:36 , Carol Cheung wrote:

> My question is: Is it possible to alter the 'some_int' column
> directly without having to create a temporary 'some_time' holding
> column?

Are you trying to alter the table to replace your some_int column
with a some_time column? I believe you can do this in two steps.

SELECT *
FROM some_data;
some_int
----------
12
345
1622
1
(4 rows)

ALTER TABLE some_data
ALTER some_int TYPE TIME WITHOUT TIME ZONE
USING CAST(to_char(some_int, 'FM99909:99') AS TIME WITHOUT
TIME ZONE);

ALTER TABLE some_data
RENAME some_int TO some_time;

SELECT *
FROM some_data;
some_time
-----------
00:12:00
03:45:00
16:22:00
00:01:00
(4 rows)

Hope this helps.

Michael Glaesemann
grzm seespotcode net

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Carol Cheung 2007-06-27 22:09:08 Re: convert column of integer type to time type?
Previous Message Carol Cheung 2007-06-27 15:36:50 convert column of integer type to time type?