Re: Number of occurrence of characters?

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Ivan Voras <ivoras(at)freebsd(dot)org>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Number of occurrence of characters?
Date: 2009-02-05 14:13:35
Message-ID: 20090205141335.GA18324@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, Feb 05, 2009 at 02:31:24PM +0100, Ivan Voras wrote:
> The problem is how to do it efficiently. I see there isn't a built-in
> function that counts character occurrences so I'd have to write it
> myself. An additional constraint is that it must be implemented with
> built-in capabilities, i.e. SQL and plpsql languages. I can do it the
> brute force way, looping over the string and processing one by one
> character with substring(), but is there a faster way?

# select length(regexp_replace('/some/string/with/slashes', '[^/]+', '', 'g'));
length
--------
4
(1 row)

depesz

--
Linkedin: http://www.linkedin.com/in/depesz / blog: http://www.depesz.com/
jid/gtalk: depesz(at)depesz(dot)com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Heikki Linnakangas 2009-02-05 14:35:07 Re: Number of occurrence of characters?
Previous Message Gregory Stark 2009-02-05 14:04:25 Re: suggestions for postgresql setup on Dell 2950 , PERC6i controller