Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 18B7E1337B5E for ; Tue, 28 Dec 2010 21:36:30 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 20916-09 for ; Wed, 29 Dec 2010 01:36:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 6C3371337B5C for ; Tue, 28 Dec 2010 21:36:22 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oBT1aKfi013703; Tue, 28 Dec 2010 20:36:20 -0500 (EST) To: David Rericha cc: pgsql-admin@postgresql.org Subject: Re: date out of range for timestamp In-reply-to: <4D1A7AB3.4010008@healthcareoss.com> References: <4D1A7AB3.4010008@healthcareoss.com> Comments: In-reply-to David Rericha message dated "Tue, 28 Dec 2010 18:02:59 -0600" Date: Tue, 28 Dec 2010 20:36:20 -0500 Message-ID: <13702.1293586580@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/198 X-Sequence-Number: 36427 David Rericha writes: > I have a 21 GB database in version 8.4.5 that is giving me a curious > error when I perform a query on one of the tables: > select count(*) from moms_outside_report where outreport_date <= > '12/10/2010'; > ERROR: date out of range for timestamp Did you really truly type the query just like that, or was the comparison "constant" actually a placeholder of some sort? The only way I can see for that query to invoke the places where that error message can be produced is if what you were really doing was "date_column <= timestamp_constant". And an unmarked literal string being compared to a date column would *not* get interpreted as a timestamp. But if you were issuing this through some client-side driver that was marking the parameter as being of type timestamp, it's believable. Anyway, assuming that the query really is date <= timestamp, the problem is you've got some wacko date value in the table, and when the backend tries to promote that date to timestamp so it can do the comparison, it fails. Per the fine manual, dates go out to about 5 million AD while timestamps only reach about 300 thousand AD. Try select * from moms_outside_report where outreport_date > '290000-01-01'::date or outreport_date < '4700-01-01 BC'::date; to find the bad values. Or maybe better, search for anything outside the range of what you think the entries ought to be. regards, tom lane