Skip site navigation (1) Skip section navigation (2)

Number of occurrence of characters?

From: Ivan Voras <ivoras(at)freebsd(dot)org>
To: pgsql-performance(at)postgresql(dot)org
Subject: Number of occurrence of characters?
Date: 2009-02-05 13:31:24
Message-ID: gmepnh$7da$1@ger.gmane.org (view raw or flat)
Thread:
Lists: pgsql-performance
Hi,

I have a need to fairly often select data where the number of
occurrences of a character in the field is "x". Semantically, it's
literally "SELECT something FROM table WHERE numch('/', field)=$x".

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?

Whatever the function is, I intend to create an index on it.

Responses

pgsql-performance by date

Next:From: Gregory StarkDate: 2009-02-05 14:04:25
Subject: Re: suggestions for postgresql setup on Dell 2950 , PERC6i controller
Previous:From: Matt BurkeDate: 2009-02-05 13:12:15
Subject: Re: suggestions for postgresql setup on Dell 2950 , PERC6i controller

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group