Re: substring result

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: substring result
Date: 2006-02-13 12:06:28
Message-ID: 20060213120628.GB30335@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

am 13.02.2006, um 10:53:48 +0000 mailte Luis Silva folgendes:
>
> I there!! I'm trying to use regular expressions with postgresql. My
> objective is to get from a long string the information that I need.
> For example
>
> "name='joe' , address='portugal' " and I need to get 'joe' and 'portugal'.
> can I do it with select substring()? if I can,how? tks a lot

test=# select * from foo;
string
---------------------------------
name='joe' , address='portugal'
(1 row)

Write a function:
- count the fields separeted by ',' and then for every field:

test=# select regexp_replace(split_part(string,',',1), '\\m.*=', '') from foo;
regexp_replace
----------------
'joe'
(1 row)

test=# select regexp_replace(split_part(string,',',2), '\\m.*=', '') from foo;
regexp_replace
----------------
'portugal'
(1 row)

You can with trim() remove spaces if you need.

HTH, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47215, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message GIGI 2006-02-13 12:21:48 BLOB type storing... once again?
Previous Message Luis Silva 2006-02-13 10:53:48 substring result