From: Tom Lane Date: Sat, 7 Oct 2006 00:12:12 +0000 (+0000) Subject: Fix string_to_array() to correctly handle the case where there are X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=b0d6fbe1303aabe8f3a5e8a40bdd1abca1ded864;p=users%2Fbernd%2Fpostgres.git Fix string_to_array() to correctly handle the case where there are overlapping possible matches for the separator string, such as string_to_array('123xx456xxx789', 'xx'). Also, revise the logic of replace(), split_part(), and string_to_array() to avoid O(N^2) work from redundant searches and conversions to pg_wchar format when there are N matches to the separator string. Backpatched the full patch as far as 8.0. 7.4 also has the bug, but the code has diverged a lot, so I just went for a quick-and-dirty fix of the bug itself in that branch. --- diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 88a6b8a92c..9133ebac81 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -779,6 +779,8 @@ text_position(Datum str, Datum search_str, int matchnum) pos = p + 1; break; } + p1 += len2 - 1; + p += len2 - 1; } p1++; } @@ -809,6 +811,8 @@ text_position(Datum str, Datum search_str, int matchnum) pos = p + 1; break; } + p1 += len2 - 1; + p += len2 - 1; } p1++; }