| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
| Cc: | Andreas Joseph Krogh <andreas(at)visena(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Daterange question |
| Date: | 2024-01-20 05:35:07 |
| Message-ID: | 2922215.1705728907@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andreas Joseph Krogh | 2024-01-20 06:10:49 | Re: Daterange question |
| Previous Message | Andreas Joseph Krogh | 2024-01-20 05:28:15 | Re: Daterange question |