From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: lucvanlind.en@gmail.com <lucvanlind.en@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #18239: select position ('' in 'A') returns 1
Date: Sun, 10 Dec 2023 11:13:00 -0500
Message-ID: <1886034.1702224780@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwY3+nE9QjU0vmyDHw1VAH8SWTJX_noX4QZnXDMjpNVMEQ@mail.gmail.com>
References: <18239-50b7f8e43ec7be76@postgresql.org>
<CAKFQuwY3+nE9QjU0vmyDHw1VAH8SWTJX_noX4QZnXDMjpNVMEQ@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sunday, December 10, 2023, PG Bug reporting form <noreply@postgresql.org>
> 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 <string position expression> is specified, then
Case:
a) If the first <string value expression> 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
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, lucvanlind.en@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18239: select position ('' in 'A') returns 1
In-Reply-To: <1886034.1702224780@sss.pgh.pa.us>
* 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