Re: [GENERAL] Regular expressions syntax: is \ the escape character ? - Mailing list pgsql-general

From Chris Jones
Subject Re: [GENERAL] Regular expressions syntax: is \ the escape character ?
Date
Msg-id x64saioizd.fsf@reddwarf.rightnowtech.com
Whole thread Raw
In response to Regular expressions syntax: is \ the escape character ?  (Gabriel Fernandez <gabi@unica.edu>)
List pgsql-general
Gabriel Fernandez <gabi@unica.edu> writes:

> The only problem i have is when i want to escape a single quote (') or the
> backslash (\).
>
> For example: i have one row with the value 'ONE\SECOND'
>
> I try to recover it doing (from psql frontend):
>
> select field1 from table1 where field1 ~* 'ONE\\\'  ;

Heh.  This will probably work if you use *four* backslashes.  The
first time it gets parsed, 'ONE\\\\' -> 'ONE\\', because each '\\'
sequence will reduce to a single '\'.  Then the second time it gets
parsed, the '\\' -> '\', which is what you want.

(Haven't tested it, but I've seen similar things in other places.)

Chris

--
---------------------------------------------------- cjones@rightnowtech.com
Chris Jones
           System Administrator, Right Now Technologies, Inc.
"Is this going to be a stand-up programming session, sir, or another bug hunt?"

pgsql-general by date:

Previous
From: JB
Date:
Subject: Re: [GENERAL] 50 MB Table
Next
From: Ron Atkins
Date:
Subject: Re: DHCP and pg_hba.conf