Re: using possibly null timestamptz columns

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: James Cloos <cloos(at)jhcloos(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: using possibly null timestamptz columns
Date: 2016-09-29 13:05:48
Message-ID: 5086.1475154348@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

James Cloos <cloos(at)jhcloos(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2016-09-29 13:15:22 Re: using possibly null timestamptz columns
Previous Message James Cloos 2016-09-29 12:35:30 using possibly null timestamptz columns