Re: postgres function - Mailing list pgsql-general

From Jim Nasby
Subject Re: postgres function
Date
Msg-id 56217800.8020108@BlueTreble.com
Whole thread Raw
In response to postgres function  (Ramesh T <rameshparnanditech@gmail.com>)
List pgsql-general
On 10/14/15 8:38 AM, Ramesh T wrote:
> Hi All,
>            Do we have  function like  regexp_substr in postgres..?
>
> in oracle this function seach the - from 1 to 2 and return result,
> regexp_substr(PART_CATG_DESC,'[^-]+', 1, 2)

Use regexp_split_to_array(string text, pattern text [, flags text ]):

SELECT regexp_split_to_array('1-2-3-4-5', '-');
  regexp_split_to_array
-----------------------
  {1,2,3,4,5}

If you just want one part of the array:

SELECT (regexp_split_to_array('1-2-3-4-5', '-'))[2];
  regexp_split_to_array
-----------------------
  2

(Note the extra ()s)

If that's not what you need then as David suggested please provide a few
input values and what you expect as your *final* output. IE: tell us
what you're ultimately trying to do, instead of just asking about regexp
matching. There may be a much better way to do it in Postgres than
whatever you were doing in Oracle.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


pgsql-general by date:

Previous
From: Jim Nasby
Date:
Subject: Re: converting in() clause into a with prefix?
Next
From: Karsten Hilbert
Date:
Subject: Re: ID column naming convention