pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Andreas Joseph Krogh <andreas@visena.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Daterange question
Date: Sat, 20 Jan 2024 00:35:07 -0500
Message-ID: <2922215.1705728907@sss.pgh.pa.us> (raw)
In-Reply-To: <253fb378-5d21-4605-a444-9338990253a2@aklaver.com>
References: <VisenaEmail.2.c34e09422a661ed9.18d2509f980@origo-test01.app.internal.visena.net>
	<253fb378-5d21-4605-a444-9338990253a2@aklaver.com>

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





view thread (5+ messages)  latest in thread

Message-ID: <2922215.1705728907@sss.pgh.pa.us>
Permalink:  ../2922215.1705728907@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2922215.1705728907@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, andreas@visena.com
  Subject: Re: Daterange question
  In-Reply-To: <2922215.1705728907@sss.pgh.pa.us>
  References: <VisenaEmail.2.c34e09422a661ed9.18d2509f980@origo-test01.app.internal.visena.net> <253fb378-5d21-4605-a444-9338990253a2@aklaver.com> <2922215.1705728907@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox