agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: James Cloos <cloos@jhcloos.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: using possibly null timestamptz columns
Date: Thu, 29 Sep 2016 09:05:48 -0400
Message-ID: <5086.1475154348@sss.pgh.pa.us> (raw)
In-Reply-To: <m3a8eqx4rx.fsf@carbon.jhcloos.org>
References: <m3a8eqx4rx.fsf@carbon.jhcloos.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

James Cloos <cloos@jhcloos.com> 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



view thread (4+ messages)  latest in thread

Message-ID: <5086.1475154348@sss.pgh.pa.us>
Permalink:  ../5086.1475154348@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5086.1475154348@sss.pgh.pa.us

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, cloos@jhcloos.com
  Subject: Re: using possibly null timestamptz columns
  In-Reply-To: <5086.1475154348@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox