Re: postgres function - Mailing list pgsql-general

From Geoff Winkless
Subject Re: postgres function
Date
Msg-id CAEzk6fcQTmuUU_CC6_=9HRgHQCAKDRETxersPyDPxSJoMa=2vA@mail.gmail.com
Whole thread Raw
In response to Re: postgres function  (Ramesh T <rameshparnanditech@gmail.com>)
List pgsql-general
Well you could use

SELECT LENGTH(REGEXP_REPLACE('123-987-123', '(([^-]*-){2}).*', '\1'));

Not pretty, but it works.

Geoff

On 15 October 2015 at 15:05, Ramesh T <rameshparnanditech@gmail.com> wrote:
'123-987-123' it is not fixed some times it may be '1233-9873-123-098'
as you said it's fixed,

changes the values in middle of the -

sometimes times i need 1233 and 098 or 9873,first position  i'll find direct for second variable we don't know where it's end with -

i.e ,
i need to find second postition of the variable between the '-'


                     
On Thu, Oct 15, 2015 at 6:32 PM, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thu, Oct 15, 2015 at 8:32 AM, Ramesh T <rameshparnanditech@gmail.com> wrote:
 select position('-' in '123-987-123')
position
---
4
But I want second occurrence,
position
-------------
8

plz any help..?

 
SELECT length((regexp_matches('123-987-123', '(\d{3}-\d{3}-)\d{3}'))[1])

David J.



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: question
Next
From: "David G. Johnston"
Date:
Subject: Re: How can I use crosstab functons in PostgreSQL 9.3?