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