Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpbCO-0005G6-CN for pgsql-sql@arkaria.postgresql.org; Thu, 29 Sep 2016 13:16:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bpbCN-0006w5-VV for pgsql-sql@arkaria.postgresql.org; Thu, 29 Sep 2016 13:16:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bpbBP-0003OG-S7 for pgsql-sql@postgresql.org; Thu, 29 Sep 2016 13:15:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bpbBN-0003Fm-Gy for pgsql-sql@postgresql.org; Thu, 29 Sep 2016 13:15:26 +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 u8TDFMZR005498; Thu, 29 Sep 2016 09:15:22 -0400 From: Tom Lane To: James Cloos cc: pgsql-sql@postgresql.org Subject: Re: using possibly null timestamptz columns In-reply-to: <5086.1475154348@sss.pgh.pa.us> References: <5086.1475154348@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 29 Sep 2016 09:05:48 -0400" Date: Thu, 29 Sep 2016 09:15:22 -0400 Message-ID: <5497.1475154922@sss.pgh.pa.us> X-Pg-Spam-Score: -4.9 (----) 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 I wrote: > You could try constructing a GIST or SPGIST index on the ranges > tstzrange(s, e), where you'd have to do something to convert null > endpoints to infinities, and then probing with WHERE rangeexpr @> now(). Or actually, it looks like tstzrange() already does the right thing: regression=# select tstzrange(now(), null); tstzrange ----------------------------------- ["2016-09-29 09:12:14.79429-04",) (1 row) regression=# select tstzrange(null, now()); tstzrange ------------------------------------ (,"2016-09-29 09:12:33.632327-04") (1 row) So this just reduces to WHERE tstzrange(s, e) @> now(). regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql