pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim Buttafuoco <jim@contactbda.com>
To: mailreg@numerixtechnology.de
To: pgsql-sql@postgresql.org
Subject: Re: SELECT substring with regex
Date: Fri, 7 Jul 2006 16:34:32 -0400
Message-ID: <20060707203420.M77919@contactbda.com> (raw)
In-Reply-To: <44AEB4C6.9000903@numerixtechnology.de>
References: <44AE66E0.1040606@numerixtechnology.de>
	<200607071659.14940.gary.stainburn@ringways.co.uk>
	<44AE9B4F.1020401@numerixtechnology.de>
	<a55915760607071137q2c70346cp5b30cac14beaf1e7@mail.gmail.com>
	<44AEB4C6.9000903@numerixtechnology.de>

use plperl


---------- Original Message -----------
From: T E Schmitz <mailreg@numerixtechnology.de>
To: pgsql-sql@postgresql.org
Sent: Fri, 07 Jul 2006 20:23:50 +0100
Subject: Re: [SQL] SELECT substring with regex

> Rodrigo De Leon wrote:
> > On 7/7/06, T E Schmitz <mailreg@numerixtechnology.de> wrote:
> > 
> >> But that takes me to the next problem:
> >>
> >> For the sake of the example I simplified the regular pattern.
> >> In reality, BASE_NAME might be:
> >>
> >> 28mm
> >> 28-70mm
> >>
> >> So the reg. expr. requires brackets:
> >>
> >> substring (NAME, '^(\\d+(-\\d+)?mm)' ) as BASE_NAME
> >>
> >> Actually, the pattern is more complex than that and I cannot see how I
> >> can express it without brackets.
> > 
> > 
> > Maybe:
> > 
> > select
> > substring ('28-70mm LD AD Asp XR Macro', '^[\\d-]*mm' ) as BASE_NAME
> 
> Sorry, but that would also capture something like
> 10-30-59mm
> 
> The pattern describes either a single length (120 millimeters) or a 
> range (30 to 70 millimetres), hence:
> 
> \\d+(-\\d+)?mm
> 
> The ? quantifier refers to the combination of '-' and digits and has to 
> be bracketed.
> 
> If the brackets cannot be avoided in the expression, your original 
> suggestion might come in handy though:
> 
> SELECT
> substring (NAME, '^\\d+(-\\d+)?mm') AS BASE_NAME ,
> substr(
>      NAME
>      , char_length(
>          substring (NAME, '^\\d+(-\\d+)?mm')
>      ) + 2
> ) AS SUFFIX
> 
> Still, I'd be interested to know whether there is a 'more elegant' solution.
> 
> --
> 
> Regards,
> 
> Tarlika Elisabeth Schmitz
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org
------- End of Original Message -------




view thread (20+ messages)  latest in thread

Message-ID: <20060707203420.M77919@contactbda.com>
Permalink:  ../20060707203420.M77919@contactbda.com/
Also on:    postgresql.org/message-id/20060707203420.M77919@contactbda.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: jim@contactbda.com, mailreg@numerixtechnology.de
  Subject: Re: SELECT substring with regex
  In-Reply-To: <20060707203420.M77919@contactbda.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