Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL8Zc-0003TS-0n for pgsql-admin@arkaria.postgresql.org; Thu, 26 Jan 2023 20:10:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pL8Za-0006gi-V1 for pgsql-admin@arkaria.postgresql.org; Thu, 26 Jan 2023 20:10:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL8Za-0006gZ-Kj for pgsql-admin@lists.postgresql.org; Thu, 26 Jan 2023 20:10:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pL8ZY-0004Qw-EK for pgsql-admin@lists.postgresql.org; Thu, 26 Jan 2023 20:10:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 30QKAAWc3165932; Thu, 26 Jan 2023 15:10:10 -0500 From: Tom Lane To: "David G. Johnston" cc: Raj kumar , Pgsql-admin Subject: Re: Conversion of a column from Integer format type to 'timestamp with time zone' In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Thu, 26 Jan 2023 13:02:00 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3165930.1674763810.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 26 Jan 2023 15:10:10 -0500 Message-ID: <3165931.1674763810@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Thu, Jan 26, 2023 at 12:45 PM Raj kumar wr= ote: >> Hi, there is a column 'created' in the 'customers' table which is actua= lly >> 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' fo= rmat? >> = >> 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 th= at > 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: =3D# 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