From: Emi Lu <emilu@encs.concordia.ca>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: "Rodrigo E. De León Plicet" <rdeleonp@gmail.com>
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 13:28:14 -0500
Message-ID: <47B5D9BE.7050002@encs.concordia.ca> (raw)
In-Reply-To: <162867790802151023i5a2276bj17f3f666aa4e6827@mail.gmail.com>
References: <47B5B944.4010203@encs.concordia.ca>
<a55915760802150946t7cd4b0a6x7ba31f28c6948bff@mail.gmail.com>
<162867790802151023i5a2276bj17f3f666aa4e6827@mail.gmail.com>
Pavel Stehule wrote:
> Hello
>
> what about
>
> CREATE OR REPLACE FUNCTION Foobar(text, text)
> RETURNS integer AS $$
> SELECT array_upper(string_to_array($1,$2),1) - 1;
> $$ LANGUAGE SQL IMMUTABLE;
>
> On 15/02/2008, Rodrigo E. De León Plicet <rdeleonp@gmail.com> wrote:
>> 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)
>>
If there is not a system func for this, I will do this way.
Thank you for all inputs.
Ly
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: emilu@encs.concordia.ca, pavel.stehule@gmail.com, rdeleonp@gmail.com
Subject: Re: String function to Find how many times str2 is in str1?
In-Reply-To: <47B5D9BE.7050002@encs.concordia.ca>
* 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