Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMB1M-0000nC-Sq for pgsql-hackers@arkaria.postgresql.org; Thu, 02 May 2019 12:41:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hMB1L-0004eD-N1 for pgsql-hackers@arkaria.postgresql.org; Thu, 02 May 2019 12:41:03 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMB1L-0004e5-ED for pgsql-hackers@lists.postgresql.org; Thu, 02 May 2019 12:41:03 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hMB1I-0004PF-PS for pgsql-hackers@lists.postgresql.org; Thu, 02 May 2019 12:41:03 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id DCF5DA01D6 for ; Thu, 2 May 2019 14:40:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id CuDDSlB0yMi2 for ; Thu, 2 May 2019 14:40:53 +0200 (CEST) Message-ID: <77f24ea19ab802bc9bc60ddbb8977ee2d646aec1.camel@cybertec.at> Subject: Bad canonicalization for dateranges with 'infinity' bounds From: Laurenz Albe To: pgsql-hackers@lists.postgresql.org Date: Thu, 02 May 2019 14:40:52 +0200 Organization: Cybertec Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-INFINITE has: Also, some element types have a notion of “infinity”, but that is just another value so far as the range type mechanisms are concerned. For example, in timestamp ranges, [today,] means the same thing as [today,). But [today,infinity] means something different from [today,infinity) — the latter excludes the special timestamp value infinity. This does not work as expected for ranges with discrete base types, notably daterange: test=> SELECT '[2000-01-01,infinity]'::daterange; daterange ----------------------- [2000-01-01,infinity) (1 row) test=> SELECT '(-infinity,2000-01-01)'::daterange; daterange ------------------------ [-infinity,2000-01-01) (1 row) This is because "daterange_canonical" makes no difference for 'infinity', and adding one to infinity does not change the value. I propose the attached patch which fixes the problem. Yours, Laurenz Albe