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 [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly