Re: patch adding new regexp functions

Поиск
Список
Период
Сортировка
От Mark Dilger
Тема Re: patch adding new regexp functions
Дата
Msg-id 45D7570A.2050502@markdilger.com
обсуждение исходный текст
Ответ на Re: patch adding new regexp functions  (Jeremy Drake <pgsql@jdrake.com>)
Список pgsql-patches
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

В списке pgsql-patches по дате отправления:

Предыдущее
От: Jeremy Drake
Дата:
Сообщение: Re: patch adding new regexp functions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: patch adding new regexp functions