mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Handle empty-string edge cases correctly in strpos().
Commit 9556aa01c
rearranged the innards of text_position() in a way
that would make it not work for empty search strings. Which is fine,
because all callers of that code special-case an empty pattern in
some way. However, the primary use-case (text_position itself) got
special-cased incorrectly: historically it's returned 1 not 0 for
an empty search string. Restore the historical behavior.
Per complaint from Austin Drenski (via Shay Rojansky).
Back-patch to v12 where it got broken.
Discussion: https://postgr.es/m/CADT4RqAz7oN4vkPir86Kg1_mQBmBxCp-L_=9vRpgSNPJf0KRkw@mail.gmail.com
This commit is contained in:
@ -1371,6 +1371,24 @@ SELECT strpos('abcdef', 'xy') AS "pos_0";
|
||||
0
|
||||
(1 row)
|
||||
|
||||
SELECT strpos('abcdef', '') AS "pos_1";
|
||||
pos_1
|
||||
-------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SELECT strpos('', 'xy') AS "pos_0";
|
||||
pos_0
|
||||
-------
|
||||
0
|
||||
(1 row)
|
||||
|
||||
SELECT strpos('', '') AS "pos_1";
|
||||
pos_1
|
||||
-------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- test replace
|
||||
--
|
||||
|
@ -479,6 +479,12 @@ SELECT strpos('abcdef', 'cd') AS "pos_3";
|
||||
|
||||
SELECT strpos('abcdef', 'xy') AS "pos_0";
|
||||
|
||||
SELECT strpos('abcdef', '') AS "pos_1";
|
||||
|
||||
SELECT strpos('', 'xy') AS "pos_0";
|
||||
|
||||
SELECT strpos('', '') AS "pos_1";
|
||||
|
||||
--
|
||||
-- test replace
|
||||
--
|
||||
|
Reference in New Issue
Block a user