Re: patch adding new regexp functions

From: Jeremy Drake <pgsql(at)jdrake(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>, Neil Conway <neilc(at)samurai(dot)com>, David Fetter <david(at)fetter(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: patch adding new regexp functions
Date: 2007-02-15 23:15:31
Message-ID: Pine.BSO.4.64.0702151506140.18849@resin.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Dunstan 2007-02-15 23:58:18 Re: "anyelement2" pseudotype
Previous Message Gregory Stark 2007-02-15 23:03:26 Short varlena header bit-packing options

Browse pgsql-patches by date

  From Date Subject
Next Message Alvaro Herrera 2007-02-16 00:07:18 remove dbname arg from bootstrap mode
Previous Message David Fetter 2007-02-15 20:10:56 Re: patch adding new regexp functions