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 9139ECD085 for ; Thu, 10 Jul 2003 20:12: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 81914-09 for ; Thu, 10 Jul 2003 17:12:10 -0300 (ADT) Received: from mailav.tor1.inquent.com (mail.inquent.com [216.208.117.106]) by svr1.postgresql.org (Postfix) with ESMTP id 01536CD318 for ; Thu, 10 Jul 2003 10:42:20 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 3F3F410258; Thu, 10 Jul 2003 09:35:50 -0400 (EDT) Received: from [10.0.2.7] (unknown [10.0.2.7]) by mailav.tor1.inquent.com (Postfix) with ESMTP id 5B8B610248; Thu, 10 Jul 2003 09:35:48 -0400 (EDT) Subject: Re: substr_count From: Rod Taylor To: Tom Rochester Cc: pgsql-sql@postgresql.org In-Reply-To: <3F0CEDC8.9000304@chu.com.au> References: <3F0CEDC8.9000304@chu.com.au> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-J5vCtjOMb9xNbAt4PTh1" Message-Id: <1057844586.46100.129.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.0 Date: 10 Jul 2003 13:43:06 +0000 X-Virus-Scanned: by AMaViS perl-11 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/131 X-Sequence-Number: 14245 --=-J5vCtjOMb9xNbAt4PTh1 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, 2003-07-10 at 04:38, Tom Rochester wrote: > Hey all, >=20 > I would like to achive something along the lines of: >=20 > SELECT field FROM table WHERE field ILIKE '$searchterm' ORDER BY=20 > substr_count(field, '$searchterm'); >=20 > Of course the substr_count function does not exist. Is there anyway to=20 > do this? >=20 > I had a thought char_count(replace(field, !$searchterm, '')) might do=20 > the job but replace doesn't allow for 'replace everything NOT string'; How about: (char_count(field) - char_count(replace(field, $searchterm, ''))) --=-J5vCtjOMb9xNbAt4PTh1 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA/DW1p6DETLow6vwwRAtilAJ9TcSQPTH7VbwSFffOM/uLtL/dixQCcDz4O mbOsWD8pcVoRJu0dyRTqSQg= =9rEB -----END PGP SIGNATURE----- --=-J5vCtjOMb9xNbAt4PTh1--