On Thu, 15 Feb 2007, Alvaro Herrera wrote:
> Jeremy Drake wrote:
>
> > The functions added are:
> > * regexp_split(str text, pattern text) RETURNS SETOF text
> > regexp_split(str text, pattern text, flags text) RETURNS SETOF text
> > returns each section of the string delimited by the pattern.
> > * regexp_matches(str text, pattern text) RETURNS text[]
> > returns all capture groups when matching pattern against string in an
> > array
> > * regexp_matches(str text, pattern text, flags text) RETURNS SETOF
> > (prematch text, fullmatch text, matches text[], postmatch text)
> > returns all capture groups when matching pattern against string in an
> > array. also returns the entire match in fullmatch. if the 'g' option
> > is given, returns all matches in the string. if the 'r' option is
> > given, also return the text before and after the match in prematch and
> > postmatch respectively.
>
> I think the position the match is in could be important. I'm wondering
> if you could define them like
>
> create type re_match(match text, position int)
> regexp_split(str text, pattern text) returns setof re_match
So it looks like the issues are:
1. regexp_matches without flags has a different return type than
regexp_matches with flags. I can make them return the same OUT
parameters, but should I declare it as returning SETOF when I know
for a fact that the no-flags version will never return more than one
row?
2. regexp_split does not represent the order of the results. I can do
something like:
regexp_split(str text, pattern text[, flags text], OUT result text, OUT
startpos int) RETURNS SETOF record;
It could also have the int being a simple counter to represent the
relative order, rather than the position.
Thoughts? Do these changes address the issues recently expressed?
--
I have yet to see any problem, however complicated, which, when looked
at in the right way, did not become still more complicated.
-- Poul Anderson