Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id BC44C2E0031 for ; Fri, 15 Feb 2008 13:46:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 55880-01 for ; Fri, 15 Feb 2008 13:46:22 -0400 (AST) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by postgresql.org (Postfix) with ESMTP id 3B9352E002C for ; Fri, 15 Feb 2008 13:46:23 -0400 (AST) Received: by an-out-0708.google.com with SMTP id c36so176239ana.33 for ; Fri, 15 Feb 2008 09:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=eqB04CN3utx1JPJaQUu/WASDY0awT3SndIUUmIzNRLg=; b=cQBWm60Gx+A045vEwP5bdhyhUqhwjYiURbVk/PpMa1qpRIexZp86mfvbhb6QtJA2jzqQnCYWZ8qmHEZoAUn+0ai25+YtQHWBMLCB5jQoOTzX3p8yeSCtEqjvtrmLhUVGiinaa79vZnl5/VjiwCA0lYH99GfAUyYf8ClvsHztxKw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=kJD7gbdqSyZl5KMQoqQfPJy11IAGxvqXZYQeFv4vCkOaDuEJdyuhKAFkXR09Ce+7ieYZ0jILTonuaFxF/x1jI7Rjr6z+knwsqT5UxYIdGjajHRaAhlrwQ5eGTDh7oVfEmoI2jbxt0VVof45zwiPZbt84YVi5UTuw698EAvA2qUU= Received: by 10.100.241.17 with SMTP id o17mr4136391anh.106.1203097582376; Fri, 15 Feb 2008 09:46:22 -0800 (PST) Received: by 10.100.122.9 with HTTP; Fri, 15 Feb 2008 09:46:22 -0800 (PST) Message-ID: Date: Fri, 15 Feb 2008 12:46:22 -0500 From: "=?UTF-8?Q?Rodrigo_E._De_Le=C3=B3n_Plicet?=" To: emilu@encs.concordia.ca Subject: Re: String function to Find how many times str2 is in str1? Cc: "PostgreSQL SQL List" In-Reply-To: <47B5B944.4010203@encs.concordia.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <47B5B944.4010203@encs.concordia.ca> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/130 X-Sequence-Number: 30221 On Fri, Feb 15, 2008 at 11:09 AM, Emi Lu wrote: > Str1 = "test test caa dtest testing EndofString"; > Str2 = " "; > > select funcName(Str1, Str2); > > return 5 CREATE OR REPLACE FUNCTION FOOBAR(TEXT,TEXT) RETURNS INT AS $$ SELECT(LENGTH($1) - LENGTH(REPLACE($1, $2, ''))) / LENGTH($2) ; $$ LANGUAGE SQL IMMUTABLE; SELECT FOOBAR('test test caa dtest testing EndofString', ' '); foobar -------- 5 (1 row) Good luck.