Re: Conversion of a column from Integer format type to 'timestamp with time zone'

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Raj kumar <rajkumar820999(at)gmail(dot)com>, Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Conversion of a column from Integer format type to 'timestamp with time zone'
Date: 2023-01-26 20:10:10
Message-ID: 3165931.1674763810@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thu, Jan 26, 2023 at 12:45 PM Raj kumar <rajkumar820999(at)gmail(dot)com> wrote:
>> Hi, there is a column 'created' in the 'customers' table which is actually
>> supposed to be a 'timestamp with time zone' column but stored in this
>> Integer format. How do I typecast this to 'timestamp with time zone' format?
>>
>> select created from customers limit 3;
>> created
>> ---------------
>> 1521521848681
>> 1508995056368
>> 1521559994299
>> (3 rows)

> We have no way of knowing what the corresponding point-in-time a 0 in that
> column represents. Or, for that matter, what a 1 means.

A plausible guess is that those are Unix timestamps expressed in
milliseconds, in which case you could do this:

=# select to_timestamp(1521521848681 / 1000.0);
to_timestamp
----------------------------
2018-03-20 00:57:28.681-04
(1 row)

But really you need to find out, not guess.

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Laurenz Albe 2023-01-26 20:44:35 Re: Problems with unique constraints
Previous Message David G. Johnston 2023-01-26 20:02:00 Re: Conversion of a column from Integer format type to 'timestamp with time zone'