Re: substr_count

From: Rod Taylor <rbt(at)rbt(dot)ca>
To: Tom Rochester <tomr(at)chu(dot)com(dot)au>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: substr_count
Date: 2003-07-10 13:43:06
Message-ID: 1057844586.46100.129.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 2003-07-10 at 04:38, Tom Rochester wrote:
> Hey all,
>
> I would like to achive something along the lines of:
>
> SELECT field FROM table WHERE field ILIKE '$searchterm' ORDER BY
> substr_count(field, '$searchterm');
>
> Of course the substr_count function does not exist. Is there anyway to
> do this?
>
> I had a thought char_count(replace(field, !$searchterm, '')) might do
> the job but replace doesn't allow for 'replace everything NOT string';

How about:

(char_count(field) - char_count(replace(field, $searchterm, '')))

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Rod Taylor 2003-07-10 13:47:37 Re: help yourself by helping others
Previous Message Rod Taylor 2003-07-10 13:32:00 Re: Recursive request ...