Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dMwor-00030S-Fl for pgsql-sql@arkaria.postgresql.org; Mon, 19 Jun 2017 13:34:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dMwoq-0000Nv-DT for pgsql-sql@arkaria.postgresql.org; Mon, 19 Jun 2017 13:34:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dMwnr-000727-Tx for pgsql-sql@postgresql.org; Mon, 19 Jun 2017 13:33:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dMwnp-0004UJ-4d for pgsql-sql@postgresql.org; Mon, 19 Jun 2017 13:33:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v5JDXAcH019154; Mon, 19 Jun 2017 09:33:10 -0400 From: Tom Lane To: Saiful Muhajir cc: pgsql-sql@postgresql.org Subject: Re: Find rows with "timestamp out of range" In-reply-to: References: Comments: In-reply-to Saiful Muhajir message dated "Mon, 19 Jun 2017 14:11:18 +0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19152.1497879190.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 19 Jun 2017 09:33:10 -0400 Message-ID: <19153.1497879190@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Saiful Muhajir writes: > I have a table with around *133 million rows* with two timestamp columns. > While trying to copy some columns for a new database, using *\COPY *, the > error occurred with: *timestamp out of range* > *select comment_id, create_time from comments where create_time < '1 Jan > 1800';* > ERROR: 22008: timestamp out of range > LOCATION: timestamp_out, timestamp.c:226 As you can see, the error is occurring in timestamp_out(), ie in the attempt to display the specific value. You could probably do this successfully: select comment_id from comments where create_time < '1 Jan 1800'; and to fix, maybe update comments set create_time =3D '-infinity' where create_time < '1 Jan = 1800'; As to what's actually going on, we made an effort a few years back to tighten up the logic concerning exactly what is the minimum legal timestamp value --- it's somewhere in 4714BC, but as I recall, the exact boundary where it failed used to depend on your TimeZone setting. (Maybe it still does, for you ... what PG version is this exactly?) I'm betting that you have a value right on the hairy edge of failure, that was accepted when input but is now rejected during display, either because of the aforesaid logic changes or because you're using a different TimeZone setting than it was input under. It might be entertaining to try select comment_id, create_time + interval '1 year' from comments where create_time < '1 Jan 1800'; and see if that is able to produce output. regards, tom lane --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql