Re: using possibly null timestamptz columns - Mailing list pgsql-sql

From Tom Lane
Subject Re: using possibly null timestamptz columns
Date
Msg-id 5086.1475154348@sss.pgh.pa.us
Whole thread Raw
In response to using possibly null timestamptz columns  (James Cloos <cloos@jhcloos.com>)
Responses Re: using possibly null timestamptz columns
List pgsql-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



pgsql-sql by date:

Previous
From: James Cloos
Date:
Subject: using possibly null timestamptz columns
Next
From: Tom Lane
Date:
Subject: Re: using possibly null timestamptz columns