From: Alban Hertroys <haramrae@gmail.com>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Where is the tsrange() function documented?
Date: Tue, 19 Oct 2021 11:29:51 +0200
Message-ID: <ECD3A1D3-B205-4BA5-948F-A9AF3CB6AB7B@gmail.com> (raw)
In-Reply-To: <9B9DB6FE-6A6B-4D37-A767-85FD8E06D237@yugabyte.com>
References: <99FD2C6D-BF59-4D80-8335-5E67E5EA1750@yugabyte.com>
<58627e6a-ad6c-6931-2ea0-90f9d4e91cfa@aklaver.com>
<9B9DB6FE-6A6B-4D37-A767-85FD8E06D237@yugabyte.com>
> On 19 Oct 2021, at 7:11, Bryn Llewellyn <bryn@yugabyte.com> wrote:
>
> By the way, I was surprised when I tried this:
>
> with c as (
> select
> '2000-01-01'::timestamp as t1,
> '2000-01-10'::timestamp as t2,
> '2000-01-20'::timestamp as t3)
> select
> ( tsrange(t1, t3, '[)') && tsrange(t2, t2, '[)') )::text as "range result",
> ( (t1, t3) overlaps (t2, t2) )::text as "overlaps result"
> from c;
>
> and got this:
>
> range result | overlaps result
> --------------+-----------------
> false | true
>
> I can't find anything, neither on the page in question here on Range Types nor in the doc on the overlaps operator, about the semantics for when a duration collapses to an instant. Am I missing this too?
Your mistake is in how you defined an instant as a range:
with c as (
select
'2000-01-01'::timestamp as t1,
'2000-01-10'::timestamp as t2,
'2000-01-20'::timestamp as t3)
select
tsrange(t2, t2, '[)') as empty
, tsrange(t2, t2, '[]') as instant
, ( tsrange(t1, t3, '[)') && tsrange(t2, t2, '[)') )::text as "empty range result"
, ( tsrange(t1, t3, '[)') && tsrange(t2, t2, '[]') )::text as "instant range result"
from c;
empty | instant | empty range result | instant range result
-------+-----------------------------------------------+--------------------+----------------------
empty | ["2000-01-10 00:00:00","2000-01-10 00:00:00"] | false | true
(1 row)
As I read it, an empty range is not considered to overlap anything, regardless of ‘when' it was defined; it gets normalised to ‘empty’.
See also the examples in section 8.17.5 for the difference between an empty range and a single point range (what you call an instant).
Regards,
Alban Hertroys
--
There is always an exception to always.
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: haramrae@gmail.com, bryn@yugabyte.com, adrian.klaver@aklaver.com
Subject: Re: Where is the tsrange() function documented?
In-Reply-To: <ECD3A1D3-B205-4BA5-948F-A9AF3CB6AB7B@gmail.com>
References: <99FD2C6D-BF59-4D80-8335-5E67E5EA1750@yugabyte.com> <58627e6a-ad6c-6931-2ea0-90f9d4e91cfa@aklaver.com> <9B9DB6FE-6A6B-4D37-A767-85FD8E06D237@yugabyte.com> <ECD3A1D3-B205-4BA5-948F-A9AF3CB6AB7B@gmail.com>
* 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