X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 0DCAA9FB1DD for ; Fri, 7 Jul 2006 12:55:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 74362-01 for ; Fri, 7 Jul 2006 12:55:19 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by postgresql.org (Postfix) with ESMTP id 503C99FB1CE for ; Fri, 7 Jul 2006 12:55:18 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id a2so3140877ugf for ; Fri, 07 Jul 2006 08:55:17 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=KjTjazH5DTXXkURSH0bjp6ITfOkWe+4I+mWkIQy8MC5TW/QJpAH5/s41wKNUSj17RrxutWfxf4D2fnuUnUjcfUbgyFqEiHpt/Rrw2+8MbzNe7q6q5DN/2QPb3JUm/0KnQeogPvrxuvgGAQHVNUl2+D4UVyMdX1AolPcL7O0MBxc= Received: by 10.67.24.13 with SMTP id b13mr2190710ugj; Fri, 07 Jul 2006 08:55:17 -0700 (PDT) Received: by 10.67.24.20 with HTTP; Fri, 7 Jul 2006 08:55:17 -0700 (PDT) Message-ID: Date: Fri, 7 Jul 2006 10:55:17 -0500 From: "Rodrigo De Leon" Reply-To: rdeleonp@gmail.com, rdeleonp@yahoo.com To: pgsql-sql@postgresql.org Subject: Re: SELECT substring with regex In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <44AE66E0.1040606@numerixtechnology.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/103 X-Sequence-Number: 25677 On 7/7/06, T E Schmitz 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