Re: Help with regexp-query

From: Tim Landscheidt <tim(at)tim-landscheidt(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Help with regexp-query
Date: 2011-08-03 04:05:26
Message-ID: m37h6vm96h.fsf@passepartout.tim-landscheidt.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Johann Spies <jspies(at)sun(dot)ac(dot)za> wrote:

> 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.

You need to double the backslashes (e. g. "E'\\|{2,}'");
otherwise the parser will "eat" the first backslash and pass
just "|{2,}" as the second argument to regexp_replace().

Tim

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Raj Mathur ( राज =?utf-8?b?IOCkruCkvuCkpeClgeCksA==?=) 2011-08-03 15:10:17 Generic design: char vs varchar primary keys
Previous Message Mike O'Connel 2011-08-02 20:20:13 Aggregating results across multiple partitions