pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Rodrigo E. De León Plicet <rdeleonp@gmail.com>
Cc: emilu@encs.concordia.ca, "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 19:23:12 +0100
Message-ID: <162867790802151023i5a2276bj17f3f666aa4e6827@mail.gmail.com> (raw)
In-Reply-To: <a55915760802150946t7cd4b0a6x7ba31f28c6948bff@mail.gmail.com>
References: <47B5B944.4010203@encs.concordia.ca>
	<a55915760802150946t7cd4b0a6x7ba31f28c6948bff@mail.gmail.com>

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)
>
>  Good luck.
>
>  ---------------------------(end of broadcast)---------------------------
>  TIP 2: Don't 'kill -9' the postmaster
>


view thread (4+ messages)  latest in thread

Message-ID: <162867790802151023i5a2276bj17f3f666aa4e6827@mail.gmail.com>
Permalink:  ../162867790802151023i5a2276bj17f3f666aa4e6827@mail.gmail.com/
Also on:    postgresql.org/message-id/162867790802151023i5a2276bj17f3f666aa4e6827@mail.gmail.com

 · 

reply

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: pavel.stehule@gmail.com, rdeleonp@gmail.com
  Subject: Re: String function to Find how many times str2 is in str1?
  In-Reply-To: <162867790802151023i5a2276bj17f3f666aa4e6827@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