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.94.2) (envelope-from ) id 1rCMQa-00FYik-JU for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Dec 2023 16:13:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rCMQW-007czC-2I for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Dec 2023 16:13:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rCMQV-007cz4-QC for pgsql-bugs@lists.postgresql.org; Sun, 10 Dec 2023 16:13:07 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rCMQR-00BEux-Mw for pgsql-bugs@lists.postgresql.org; Sun, 10 Dec 2023 16:13:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3BAGD0qO1886035; Sun, 10 Dec 2023 11:13:00 -0500 From: Tom Lane To: "David G. Johnston" cc: "lucvanlind.en@gmail.com" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #18239: select position ('' in 'A') returns 1 In-reply-to: References: <18239-50b7f8e43ec7be76@postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Sun, 10 Dec 2023 08:20:03 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1886033.1702224780.1@sss.pgh.pa.us> Date: Sun, 10 Dec 2023 11:13:00 -0500 Message-ID: <1886034.1702224780@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Sunday, December 10, 2023, PG Bug reporting form > wrote: >> select position ('' in 'A') returns 1 >> Thus, case a field has an empty string while, checking positions in another >> string, it seems to always fit the position 1. > Just as an empty set is a subset of all sets the empty string is a > substring within all strings. Yes. This behavior is explicitly required by the SQL standard: 2) If is specified, then Case: a) If the first has a length of 0 (zero), then the result is 1 (one). b) [ otherwise, ... ] > I do not believe we document or refer to this external rule anywhere though. No, our documentation for position() is just one sentence. With the new function-table layout it'd be possible to add a second example to exhibit this behavior, but I'm not sure it's worth the trouble. Personally I don't find this surprising. regards, tom lane