pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18239: select position ('' in 'A') returns 1
3+ messages / 3 participants
[nested] [flat]

* BUG #18239: select position ('' in 'A') returns 1
@ 2023-12-10 10:22 PG Bug reporting form <noreply@postgresql.org>
  2023-12-10 15:20 ` Re: BUG #18239: select position ('' in 'A') returns 1 David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2023-12-10 10:22 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: lucvanlind.en@gmail.com

The following bug has been logged on the website:

Bug reference:      18239
Logged by:          Luc Van Linden
Email address:      lucvanlind.en@gmail.com
PostgreSQL version: 15.3
Operating system:   windows 10 64 bit
Description:        

We simplified the bug, or maybe undocumented behavior to its simplest
testcase.

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.

Not sure if this is intended or not, at least we experience this as a bug.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #18239: select position ('' in 'A') returns 1
  2023-12-10 10:22 BUG #18239: select position ('' in 'A') returns 1 PG Bug reporting form <noreply@postgresql.org>
@ 2023-12-10 15:20 ` David G. Johnston <david.g.johnston@gmail.com>
  2023-12-10 16:13   ` Re: BUG #18239: select position ('' in 'A') returns 1 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: David G. Johnston @ 2023-12-10 15:20 UTC (permalink / raw)
  To: lucvanlind.en@gmail.com <lucvanlind.en@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

On Sunday, December 10, 2023, PG Bug reporting form <noreply@postgresql.org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference:      18239
> Logged by:          Luc Van Linden
> Email address:      lucvanlind.en@gmail.com
> PostgreSQL version: 15.3
> Operating system:   windows 10 64 bit
> Description:
>
> We simplified the bug, or maybe undocumented behavior to its simplest
> testcase.
>
> 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.
>
> Not sure if this is intended or not, at least we experience this as a bug.
>
>
Just as an empty set is a subset of all sets the empty string is a
substring within all strings.

I do not believe we document or refer to this external rule anywhere though.

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #18239: select position ('' in 'A') returns 1
  2023-12-10 10:22 BUG #18239: select position ('' in 'A') returns 1 PG Bug reporting form <noreply@postgresql.org>
  2023-12-10 15:20 ` Re: BUG #18239: select position ('' in 'A') returns 1 David G. Johnston <david.g.johnston@gmail.com>
@ 2023-12-10 16:13   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2023-12-10 16:13 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: lucvanlind.en@gmail.com <lucvanlind.en@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

"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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-12-10 16:13 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-12-10 10:22 BUG #18239: select position ('' in 'A') returns 1 PG Bug reporting form <noreply@postgresql.org>
2023-12-10 15:20 ` David G. Johnston <david.g.johnston@gmail.com>
2023-12-10 16:13   ` Tom Lane <tgl@sss.pgh.pa.us>

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