Re: [SQL] Help with regexp-query

From: Charlie <scorpdaddy(at)hotmail(dot)com>
To: Johann Spies <jspies(at)sun(dot)ac(dot)za>, pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Help with regexp-query
Date: 2011-08-02 17:06:05
Message-ID: BLU0-SMTP16785319A22BF10CA427873CE3B0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

select id, regexp_replace(category, (E'\\|{2,}'), E'\|', 'g') as category from
akb_articles limit 100

Backslash in regex doubled. Added global modifier to replace all occurrences.

----- Reply message -----
From: "Johann Spies" <jspies(at)sun(dot)ac(dot)za>
Date: Thu, Jul 28, 2011 8:20 am
Subject: [SQL] Help with regexp-query
To: <pgsql-sql(at)postgresql(dot)org>

I am struggling a bit to do the following type of update in a table.

I want the content of a field updated like this:

Original:
'||||0894396e-16bf-4e63-aa52-97fe7031eec9||50a6b47c-f69c-414d-bcb6-14bbe403de5f|||'

After update:
'|0894396e-16bf-4e63-aa52-97fe7031eec9|50a6b47c-f69c-414d-bcb6-14bbe403de5f|'

in other words: change all multiple adjacent occurences of '|' to only 1.

I have tried the following query but it fails:

select id, regexp_replace(category, (E'\|{2,}'), E'\|') as category from
akb_articles limit 100

This ends with 'ERROR: invalid regular expression: quantifier operand
invalid'.

I would apreciate some help with this one please.

Regards
Johann
--
Johann Spies Telefoon: 021-808 4699
Databestuurder / Data manager

Sentrum vir Navorsing oor Evaluasie, Wetenskap en Tegnologie
Centre for Research on Evaluation, Science and Technology
Universiteit Stellenbosch.

"If any of you lack wisdom, let him ask of God, that
giveth to all men liberally, and upbraideth not; and
it shall be given him." James 1:5

Browse pgsql-sql by date

  From Date Subject
Next Message Mike O'Connel 2011-08-02 20:20:13 Aggregating results across multiple partitions
Previous Message Wes James 2011-08-02 14:13:01 Re: why these results?