X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 12FBACD58F for ; Fri, 11 Jul 2003 01:35:24 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 30725-09 for ; Thu, 10 Jul 2003 22:35:12 -0300 (ADT) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 5332BCD871 for ; Thu, 10 Jul 2003 12:44:46 -0300 (ADT) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.9/8.12.9) with ESMTP id h6AFhdE7003835; Thu, 10 Jul 2003 09:43:40 -0600 (MDT) Date: Thu, 10 Jul 2003 09:36:50 -0600 (MDT) From: "scott.marlowe" To: Tom Rochester Cc: Subject: Re: substr_count In-Reply-To: <3F0CEDC8.9000304@chu.com.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-MailScanner: Found to be clean X-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/135 X-Sequence-Number: 14249 On Thu, 10 Jul 2003, 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'; You'll likely have to code a bit in pl/pgsql. The regex capable substring of 7.3 might come in handy.