Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mclRX-0001AA-Kb for pgsql-general@arkaria.postgresql.org; Tue, 19 Oct 2021 09:29:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mclRW-0001BG-JX for pgsql-general@arkaria.postgresql.org; Tue, 19 Oct 2021 09:29:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mclRW-0001B7-9u for pgsql-general@lists.postgresql.org; Tue, 19 Oct 2021 09:29:58 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mclRT-0000my-9u for pgsql-general@lists.postgresql.org; Tue, 19 Oct 2021 09:29:57 +0000 Received: by mail-ed1-x530.google.com with SMTP id y30so9451173edi.0 for ; Tue, 19 Oct 2021 02:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=JdYI3hT28PIPosNrZSZkkZEVJYKNQqCxNfe2jAqvChc=; b=AkDSTEASRq1r6/P4K1ex8ZwK1XarT2DPhv0/RBxpcmJcuFobyPZSkU8mhroBZ4VgAq qfpm512kCLHL73g8+F7M6kIb+BSpnqkOybrFHgniErFXn+RM9aDziFI6+G6hvaWwNk7s 1cl/SRZ61NtQNUQosHkfG4OJlDeVG8Wc/G0aOt/tbGSABXJnOmP7aLX/ndpG2UcMQFCC 5eQC+ipf5c4Vu8pm3yakUK3Acx9iUT4K/xF1LbdgM9hKkzBGu/kdm7usdd8kQKlMhPcp p06S/dDM+MFiS2jhFJjIlgS+TKjzQ76n5gJB/rOyZRzW/hvEGVppjFzxT+MF3g5P786x 2C/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=JdYI3hT28PIPosNrZSZkkZEVJYKNQqCxNfe2jAqvChc=; b=VU3escOPXDyKCHQ00FbHJJQnsMYJtF7j28Qevg+m1b5eMsfqK2TDWdqV1rNJ3sz5Ri czStXtN7G7qFefGbWEGGhNj70t+SjuPFQPkz8OYamEleBO8X3VOjr3ZpNvetgPm2kKij GZNj5hSLaq0CZlYKU+w3DMm47tPnQCxYu/wl1ii2+UMlD4BPBD5pw6xKnKiu3/zxeSvy zVke5Wi6HxtHY32JPfxwHsZ2Dd+ZO1szFZSOZrYieEEp36ddwArmpZjncUr9XVyJ9X6M 7X1bb65XmBqYtZHiNnUM17cJc96NUZWu8Gkb7r2x6tFVYFRLBqMEv/Rfb9WzqVGEzhZX lkbA== X-Gm-Message-State: AOAM532rk+v0/nF4jjTdy0qtzZzDzCW1q85cnlRR5TR6nKf+aJn8ZG20 2zcDqSVKMF15Vic6lhbX7PRhyQZUi34= X-Google-Smtp-Source: ABdhPJzRq8spLn0yepvnFMpJBXZvSFeuwSnE/b12Lwe/uU+zcJTiikmv2UKXd5aJpeDfcpMi39uN3A== X-Received: by 2002:a17:907:2658:: with SMTP id ar24mr36490956ejc.405.1634635792660; Tue, 19 Oct 2021 02:29:52 -0700 (PDT) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id g22sm9934871ejd.33.2021.10.19.02.29.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Oct 2021 02:29:52 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Where is the tsrange() function documented? From: Alban Hertroys In-Reply-To: <9B9DB6FE-6A6B-4D37-A767-85FD8E06D237@yugabyte.com> Date: Tue, 19 Oct 2021 11:29:51 +0200 Cc: Adrian Klaver , pgsql-general list Content-Transfer-Encoding: quoted-printable Message-Id: References: <99FD2C6D-BF59-4D80-8335-5E67E5EA1750@yugabyte.com> <58627e6a-ad6c-6931-2ea0-90f9d4e91cfa@aklaver.com> <9B9DB6FE-6A6B-4D37-A767-85FD8E06D237@yugabyte.com> To: Bryn Llewellyn X-Mailer: Apple Mail (2.3608.120.23.2.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 19 Oct 2021, at 7:11, Bryn Llewellyn wrote: >=20 > By the way, I was surprised when I tried this: >=20 > 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; >=20 > and got this: >=20 > range result | overlaps result=20 > --------------+----------------- > false | true >=20 > 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=20 = -------+-----------------------------------------------+------------------= --+---------------------- 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 =E2=80=98when' it was defined; it gets normalised to = =E2=80=98empty=E2=80=99. 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.