Re: Qusetion re regexexp_split_to_array and last occurence

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Mike Martin <mike(at)redtux(dot)plus(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Qusetion re regexexp_split_to_array and last occurence
Date: 2019-10-08 19:26:30
Message-ID: CAKFQuwYXpzF=JKGhdXUBcSYf7NqXTMKsnbOB3XkVFg9D8=7tSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Oct 8, 2019 at 10:31 AM Mike Martin <mike(at)redtux(dot)plus(dot)com> wrote:

> arrfile=(regexp_split_to_array(NEW.tagfile,'/'))[2:];
>

string_to_array()? You aren't providing a regexp so it seems wasteful to
use the regexp engine to perform the task.

NEW.filearr
> :=arrfile[1:cardinality(arrfile)-1]||regexp_matches(arrfile[cardinality(arrfile)],'(.*)\.(.*)');
>

regexp_match()? You aren't returning a set of matches so use the scalar
function. Probably still need to deal with null properly.

Which works perfectly, except performance is 50% slower on a dataset of
> around 20k
>
> Is there a better solution
>

Probably not materially - it seems like you have to do it in two parts -
one to break apart the paths and then one to handle the fact that you want
the part subsequent to the final period (i.e., the file extension) in its
own array cell. Choosing the best function for each job will hopefully
improve matters at least a bit.

David J.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alex Williams 2019-10-09 01:01:39 pg_dump compatibility level / use create view instead of create table/rule
Previous Message Mike Martin 2019-10-08 15:51:01 Question re regexexp_split_to_array and last oc