Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xKVZt-00000000tGk-3gdt for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2026 06:50:06 +0000 Received: from localhost ([127.0.0.1]:41650 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xKVZt-00000000OUt-1B53 for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Oct 2026 06:50:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:53310) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xKKP3-0000000GkWJ-0Zmi for pgsql-bugs@lists.postgresql.org; Fri, 23 Oct 2026 18:54:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xKKP0-00000000clk-2HZg for pgsql-bugs@lists.postgresql.org; Fri, 23 Oct 2026 18:54:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=J6zns6R54QFOiwGTxnam4SjAiPpAxl6lA0qsXgSEQWM=; b=KTBr5CD+/tTo9EDyszxBRRWqAG Avje1siXQ2lOxLBBwevb0q8ikdUt0TEqy4YkIghu25AFhQs3Mxe3TUCJvehj5IClVvVf7tNyvfAZR GEnlWVqhQIXRkMbhCa+4D/xyIl+63AFvcAslYhvMyo/hTTlhK9rryN8WJCIsZ5qrvfxT01dPERwtW QVfIcu78nI62NPym2Tf70SiAII9x5kP2CDT2tS7aSw3o1EROV8xYnnb4UVrADtj6JREdC6GwjML34 9rO2bB7t+AlSIHBD8BNw9rtG3+gm82ek/3zS3Bo7KKGv6NfLEwAnFGauvs6NOw/nh8ov9K60zKKLm uFhxQw4A==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xKKOz-00000001fMP-0A9r for pgsql-bugs@lists.postgresql.org; Fri, 23 Oct 2026 18:54:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xKKOx-0000000560B-0LrH for pgsql-bugs@lists.postgresql.org; Fri, 23 Oct 2026 18:54:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19793: Range containment with empty/unbounded constant range returns true/false for NULL element To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: venu2805k@gmail.com Reply-To: venu2805k@gmail.com, pgsql-bugs@lists.postgresql.org Date: Fri, 23 Oct 2026 18:53:54 +0000 Message-ID: <19793-16d3a1bf33dff0fb@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19793 Logged by: Venu Kummari Email address: venu2805k@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 24.04, x86_64 Description: =20 Since PostgreSQL 17, "elem <@ range" and "range @> elem" return true or false instead of NULL when the element is NULL and the range is a constant that is empty or unbounded on both sides. This gives wrong query results, including in WHERE clauses: CREATE TEMP TABLE bookings(id int, booked_on date); INSERT INTO bookings VALUES (1, '2026-01-05'), (2, NULL); SELECT id FROM bookings WHERE booked_on <@ daterange(NULL, NULL); returns ids 1 and 2; only 1 is expected (PostgreSQL 16 returns only 1). The same happens with PREPARE ... WHERE booked_on <@ daterange($1, $2) executed with NULL, NULL. More directly: SELECT c, '(,)'::int4range @> c, NOT ('empty'::int4range @> c) FROM (VALUES (NULL::int), (1)) v(c); returns t and t for the NULL row; both should be NULL, since range_contains_elem and elem_contained_by_range are strict. With a sub-select around the range, which blocks the planner simplification, the result is NULL. EXPLAIN VERBOSE shows the expression replaced by the constant true. Reproduced on 17.11, 18.6 and master (126976a). Not reproducible on 16. Cause: find_simplified_clause() in src/backend/utils/adt/rangetypes.c, added in commit 075df6b20, returns makeBoolConst(false) for an empty constant range and makeBoolConst(true) for an unbounded one without considering that the element may be NULL. I have a patch for master and a back-branch version for 17/18, with regression tests; I will send them as a reply to this report. Found with a metamorphic (equivalent-query) fuzzer.