Re: SELECT substring with regex - Mailing list pgsql-sql

From Rodrigo De Leon
Subject Re: SELECT substring with regex
Date
Msg-id a55915760607070855j57b6b243lf1fd81dce1036bed@mail.gmail.com
Whole thread Raw
In response to SELECT substring with regex  (T E Schmitz <mailreg@numerixtechnology.de>)
List pgsql-sql
On 7/7/06, T E Schmitz <mailreg@numerixtechnology.de> wrote:
> I would like to split the contents of a column using substring with a
> regular expression:
>
> SELECT
>   substring (NAME, '^\\d+mm') as BASE_NAME,
>   substring (NAME, ??? ) as SUFFIX
> FROM MODEL
>
> The column contains something like
> "150mm LD AD Asp XR Macro"
> I want to split this into
> "150mm", "LD AD Asp XR Macro"
>
> How can I extract the bit following the matching substring?
>
> --
>
>
> Regards,
>
> Tarlika Elisabeth Schmitz

I'm sure there's a cleaner, regexp based approach, but how about:

SELECT
substring (NAME, '^\\d+mm') AS BASE_NAME ,
substr(       NAME       , char_length(               substring (NAME, '^\\d+mm')       ) + 2
) AS SUFFIX
FROM MODEL

Regards,

Rodrigo


pgsql-sql by date:

Previous
From: Chris Browne
Date:
Subject: Re: Alternative to serial primary key
Next
From: Richard Broersma Jr
Date:
Subject: Re: create aggregate function 'count_bool( column_name, boolean )'