Wed, 07 Jun 2006

Converting Epoch Time values To Timestamps

Just a quick one. If you've ever created a table using the number of seconds since 1970 and realised, after populating it with data, that you really need it in a TIMESTAMP type? If so, you can quickly convert it using this SQL:

ALTER TABLE entries 
   ALTER COLUMN created TYPE TIMESTAMP WITH TIME ZONE
      USING TIMESTAMP WITH TIME ZONE 'epoch' + created *interval '1 second';

With thanks to the PostgreSQL manual for saving me hours working out how to do this.

[database,PostgreSQL] | # Read Comments (1) |

Comments

Nice tip, but is there REAL advantage in TIMESTAMP instead of TIME?
Posted by Деньги at Tue Aug 29 23:24:11 2006

Name:


E-mail:


URL:


Comment:


Please enter "fudge" to prove you are a human