From: | "Rodrigo De Leon" <rdeleonp(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: SELECT substring with regex |
Date: | 2006-07-07 15:55:17 |
Message-ID: | a55915760607070855j57b6b243lf1fd81dce1036bed@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 7/7/06, T E Schmitz <mailreg(at)numerixtechnology(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Gary Stainburn | 2006-07-07 15:59:14 | Re: SELECT substring with regex |
Previous Message | Jim Buttafuoco | 2006-07-07 14:54:07 | Re: create aggregate function 'count_bool( column_name, boolean )' |