From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Ramesh T <rameshparnanditech(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: postgres function |
Date: | 2015-10-16 22:19:44 |
Message-ID: | 56217800.8020108@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | 許耀彰 | 2015-10-16 23:26:45 | postgresql table data control |
Previous Message | Jim Nasby | 2015-10-16 22:06:44 | Re: converting in() clause into a with prefix? |