From: Rodrigo E. De León Plicet <rdeleonp@gmail.com>
To: emilu@encs.concordia.ca
Cc: PostgreSQL SQL List <pgsql-sql@postgresql.org>
Subject: Re: String function to Find how many times str2 is in str1?
Date: Fri, 15 Feb 2008 12:46:22 -0500
Message-ID: <a55915760802150946t7cd4b0a6x7ba31f28c6948bff@mail.gmail.com> (raw)
In-Reply-To: <47B5B944.4010203@encs.concordia.ca>
References: <47B5B944.4010203@encs.concordia.ca>
On Fri, Feb 15, 2008 at 11:09 AM, Emi Lu <emilu@encs.concordia.ca> 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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rdeleonp@gmail.com, emilu@encs.concordia.ca
Subject: Re: String function to Find how many times str2 is in str1?
In-Reply-To: <a55915760802150946t7cd4b0a6x7ba31f28c6948bff@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox