Re: How to find the position of a characted in a string

From: "Pawel Socha" <pawel(dot)socha(at)gmail(dot)com>
To: ss_postgres <ss(dot)postgres(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: How to find the position of a characted in a string
Date: 2008-12-08 07:14:22
Message-ID: cc4f12900812072314r161e191vc9d2d0364f187c89@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

2008/12/8 ss_postgres <ss(dot)postgres(at)gmail(dot)com>:
> Hi,
>
> I am trying to find the position of a character in a string which appears
> multiple times.
>
> The POSITION function returns the position of the character when it first
> occurs.
>
> For eg:
>
> select position ( ' ' in 'Hi How are you');
>
> This returns the result as "3".
>
>
> But i need to result to be
> 3
> 7
> 11
>
>
> Can anyone please let me know what would be the best way to do this.
>
> Thanks
>

My first things:

merlin=> select distinct(x.case) from (select (case when substring('Hi
How are you' from r for 1) = ' ' then r else null end) from
generate_series(0, length('Hi How are you')) as r) as x;
case
------
3
7
11

--
Pawel Socha

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message AmitKumar Jain 2008-12-08 08:40:49 How can we see details of function in psql prompt
Previous Message ss_postgres 2008-12-08 06:30:00 How to find the position of a characted in a string