Jeremy Drake wrote:
The regexp_split function code was based on some code that a friend of
mine wrote which used PCRE rather than postgres' internal regexp support.
I don't know exactly what his use-case was, but he probably had
one because he wrote the function and had it returning SETOF text ;)
Perhaps he can share a general idea of what it was (nudge nudge)?

db=# CREATE OR REPLACE FUNCTION split(p TEXT, t TEXT) RETURNS SETOF TEXT AS $$
db$#     my ($p, $t) = @_;
db$#     return [ split(/$p/,$t) ];
db$# $$ LANGUAGE plperl;
CREATE FUNCTION
Time: 1.254 ms
db=# select distinct word from (select * from split('\\W+','mary had a little lamb, whose fleece was black as soot') as word) as ss;
  word
--------
 a
 as
 black
 fleece
 had
 lamb
 little
 mary
 soot
 was
 whose
(11 rows)

Time: 30.517 ms



As you can see, this can easily be done with a plperl function. Some people may not want to install plperl, or may not want to allow arbitrary patterns to be handed to perl in this fashion. That was not my concern. I was simply trying to see if I could make it faster in a C-language coded function.

In the end I dropped the project because the plperl function works fast enough for me and I don't have any objection to plperl from a security standpoint, etc.

mark

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org

Reply via email to