Re: Can Postgres beat Oracle for regexp_count?

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Shaozhong SHI <shishaozhong(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Can Postgres beat Oracle for regexp_count?
Date: 2022-02-04 04:32:45
Message-ID: CAHyXU0wUM56XEqq1MVhML=XV7+wTio1UwC6eJ+RxGWdmaJTJ8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Feb 2, 2022 at 4:26 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> > Given we don't have a regexp_count function this isn't surprising...
>
> FYI, it's there in HEAD.
>
> In the meantime, you could possibly do something like
>
> =# select count(*) from regexp_matches('My High Street', '([A-Z][a-z]+[\s])', 'g');
> count
> -------
> 2
> (1 row)

alternate version:
postgres=# select array_upper(regexp_split_to_array('My High Street My
High Street', 'My High Street'), 1) - 1;
?column?
──────────
2

can help to slide this into complex queries a little bit easier by
avoiding the aggregation :-).

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message rob stan 2022-02-04 06:02:02 Postgres Version Upgrade to 14.1 error
Previous Message A Shaposhnikov 2022-02-04 04:21:12 Re: increasing effective_cache_size slows down join queries by a factor of 4000x