pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rodrigo De Leon <rdeleonp@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: SELECT substring with regex
Date: Fri, 7 Jul 2006 10:55:17 -0500
Message-ID: <a55915760607070855j57b6b243lf1fd81dce1036bed@mail.gmail.com> (raw)
In-Reply-To: <a55915760607070851s2e1e36a1t6341c285a87061f3@mail.gmail.com>
References: <44AE66E0.1040606@numerixtechnology.de>
	<a55915760607070851s2e1e36a1t6341c285a87061f3@mail.gmail.com>

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



view thread (20+ messages)  latest in thread

Message-ID: <a55915760607070855j57b6b243lf1fd81dce1036bed@mail.gmail.com>
Permalink:  ../a55915760607070855j57b6b243lf1fd81dce1036bed@mail.gmail.com/
Also on:    postgresql.org/message-id/a55915760607070855j57b6b243lf1fd81dce1036bed@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rdeleonp@gmail.com
  Subject: Re: SELECT substring with regex
  In-Reply-To: <a55915760607070855j57b6b243lf1fd81dce1036bed@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox