Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iwpxF-000615-1f for pgsql-general@arkaria.postgresql.org; Wed, 29 Jan 2020 16:12:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iwpxD-0001GC-Oq for pgsql-general@arkaria.postgresql.org; Wed, 29 Jan 2020 16:12:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iwpxD-0001G5-BR for pgsql-general@lists.postgresql.org; Wed, 29 Jan 2020 16:12:35 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iwpx8-00053H-Mj for pgsql-general@lists.postgresql.org; Wed, 29 Jan 2020 16:12:33 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTPS id 00TGCKBG000731 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 29 Jan 2020 18:12:25 +0200 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id 00TGCKTS029316 for ; Wed, 29 Jan 2020 18:12:20 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) To: pgsql-general@lists.postgresql.org From: Achilleas Mantzios Subject: Exclude constraint on ranges : commutative containment : allow only complete containment Message-ID: <3b555944-1563-6614-a5d5-e0cc001aecdb@matrix.gatewaynet.com> Date: Wed, 29 Jan 2020 18:12:20 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------D3E614286DE4ACD06420A7E9" Content-Language: en-US X-Virus-Scanned: clamav-milter 0.101.4 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-28.0 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_NAUTICAL,HTML_MESSAGE autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------D3E614286DE4ACD06420A7E9 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hello Dear Postgresql ppl, I have a table with date ranges and need to express the following constraint : allow overlaps only if there is complete containment, e.g. allow values in rows like : [2020-01-01,2020-01-31) [2020-01-02,2020-01-10) [2020-01-10,2020-01-20) but disallow rows like [2020-01-02,2020-01-10) [2020-01-08,2020-01-11) I think that writing a new commutative range operator e.g. |<@@> which would return true if the left operand is either contained by or contains the right operand and false otherwise would solve this, I am just wondering if there is a more elegant and economical way to express this. (besides writing a trigger which is always an option).| -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt --------------D3E614286DE4ACD06420A7E9 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Hello Dear Postgresql ppl,
I have a table with date ranges and need to express the following constraint : allow overlaps only if there is complete containment, e.g.
allow values in rows like :
[2020-01-01,2020-01-31)
[2020-01-02,2020-01-10)
[2020-01-10,2020-01-20)

but disallow rows like

[2020-01-02,2020-01-10)
[2020-01-08,2020-01-11)

I think that writing a new commutative range operator e.g. <@@> which would return true if the left operand is either contained by or contains the right operand and false otherwise would solve this, I am just wondering if there is a more elegant and economical way to express this. (besides writing a trigger which is always an option).

-- 
Achilleas Mantzios
IT DEV Lead
IT DEPT
Dynacom Tankers Mgmt
--------------D3E614286DE4ACD06420A7E9--