Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpb3F-0004m3-IB for pgsql-sql@arkaria.postgresql.org; Thu, 29 Sep 2016 13:07:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bpb3E-0008Jl-V3 for pgsql-sql@arkaria.postgresql.org; Thu, 29 Sep 2016 13:07:01 +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 1bpb2G-0005p7-Iz for pgsql-sql@postgresql.org; Thu, 29 Sep 2016 13:06:00 +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 1bpb2B-0002ws-H3 for pgsql-sql@postgresql.org; Thu, 29 Sep 2016 13:05:59 +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 u8TD5m2D005087; Thu, 29 Sep 2016 09:05:48 -0400 From: Tom Lane To: James Cloos cc: pgsql-sql@postgresql.org Subject: Re: using possibly null timestamptz columns In-reply-to: References: Comments: In-reply-to James Cloos message dated "Thu, 29 Sep 2016 08:35:30 -0400" Date: Thu, 29 Sep 2016 09:05:48 -0400 Message-ID: <5086.1475154348@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 James Cloos writes: > Given a table with a pair of timestamptz columns (lets call them s and e) > which are typically null, is there a better way to write this where clause > snippet: > where ( s is null or s <= now() ) and ( e is null or e >= now() ) 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(). I'm not really sure how well this would perform, but certainly you're dead in the water as far as doing anything useful with regular btree indexes. 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