dbTalk Databases Forums  

[BUGS] string_to_array() is confused by ambiguous field separator

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] string_to_array() is confused by ambiguous field separator in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Lane
 
Posts: n/a

Default [BUGS] string_to_array() is confused by ambiguous field separator - 10-06-2006 , 04:13 PM






Good:

regression=# select string_to_array('123xx456xx789', 'xx');
string_to_array
-----------------
{123,456,789}
(1 row)

Not so good:

regression=# select string_to_array('123xx456xxx789', 'xx');
ERROR: negative substring length not allowed

The proximate problem is that in the inner loop in text_position(),
if it finds a match but hasn't yet found matchnum of them, it advances
only one character instead of advancing over the whole match. This
means it can report overlapping successive matches, which leads to an
invalid subscript calculation in text_to_array(). I think the correct
approach is to ignore overlapping matches, so that the result in the
second case would be
{123,456,x789}

There's another problem here, which is that the API of text_position()
is poorly chosen anyway: as defined, parsing a string of N fields
requires O(N^2) work. It'd be better to pass it a starting character
number for the search instead of a field number to find, and to break
out the setup step so that we don't have to repeat the conversion to
pg_wchar format for each field.

Any objections?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.