Count occurrences of pattern in string

From: "dario(dot)ber(at)libero(dot)it" <dario(dot)ber(at)libero(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Count occurrences of pattern in string
Date: 2009-10-20 17:04:26
Message-ID: 22733682.723081256058266115.JavaMail.defaultUser@defaultHost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I'm looking for a function to count the occurrences of a pattern in a
string. E.g. something like:

fun_count_pattern('fooXblaX', 'X')

which would
return 2 (I.e. pattern 'X' found 2 times in string 'fooXblaX').

I could write
my own function for this (probably using plpython?) but I was wandering whether
there is some function or combination of functions that I could use 'off-the-
shelf'.

Thanks very much

All the best

Dario

PS: I'm using PostgreSQL 8.3 on
Windows XP.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Wolfgang Keller 2009-10-20 17:11:53 Re: multi-company design/structure ?
Previous Message Gerhard Wiesinger 2009-10-20 16:41:54 Re: OT: Re: [sfpug] 10/13 SFPUG meeting, "The Mighty GUCS," video now available