Re: Daterange question

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Andreas Joseph Krogh <andreas@visena.com>, pgsql-general@lists.postgresql.org
Date: 2024-01-20T05:35:07Z
Lists: pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 1/19/24 20:08, Andreas Joseph Krogh wrote:
>> This seems to do what I want:
>> |NOT (drange << daterange(CURRENT_DATE, NULL, '[)'))|
>> But this doesn't use the index.
>> Any idea how to write a query so it uses the index on |drange|?

> Without the full query and the EXPLAIN output I don't see that there is 
> much that can be offered in way of an answer.

Well, we can definitively state that the NOT makes this unindexable.
You need a WHERE clause that looks like
	indexed-column indexable-operator pseudo-constant
which this isn't, nor does << have a negator operator that could
allow the NOT to be simplified out.

Wouldn't
	drange && daterange(CURRENT_DATE, NULL, '[)')
serve the purpose?  That should be indexable.

			regards, tom lane