Thread: Quoting/Escaping

Quoting/Escaping

From
Bill Sneed
Date:
I'd like to be able to find a book title that contain C++ in the
title....

select * from books where title ~* 'C++'   doesn't work.

I've tried all the basic methods of quoting the Plus (+) signs but
none seem to work...

Any hints would be most appreciated....

....Thanks...

....Bill Sneed, Prospect, Maine....

Re: [GENERAL] Quoting/Escaping

From
Ed Loehr
Date:
Bill Sneed wrote:

> I'd like to be able to find a book title that contain C++ in the
> title....
>
> select * from books where title ~* 'C++'   doesn't work.
>
> I've tried all the basic methods of quoting the Plus (+) signs but
> none seem to work...
>
> Any hints would be most appreciated....
>
> ....Thanks...
>
> ....Bill Sneed, Prospect, Maine....
>
> ************

I think the 'like' operator may do what you seek.

create table t (w varchar);
insert into t (w) values ('C++');
insert into t (w) values ('C');
select * from t where w like 'C++';
w
---
C++
(1 row)

Cheers.
Ed


Re: [GENERAL] Quoting/Escaping

From
Herouth Maoz
Date:
At 23:21 +0200 on 28/11/1999, Bill Sneed wrote:


> I'd like to be able to find a book title that contain C++ in the
> title....
>
> select * from books where title ~* 'C++'   doesn't work.
>
> I've tried all the basic methods of quoting the Plus (+) signs but
> none seem to work...
>
> Any hints would be most appreciated....

testing=> select * from test1;
tx
------------------------------------------------
I prefer Java to C++ programming.
C++ is the most complicated of all OO langagues.
Java has less inheritance, but it is simpler.
(3 rows)
testing=> select * from test1 where tx ~* 'C\\+\\+';
tx
------------------------------------------------
I prefer Java to C++ programming.
C++ is the most complicated of all OO langagues.
(2 rows)

Rationale: the string is processed in two stages. One, when the query is
read by Postgres. The other, when the regexp engine reads it. It needs to
have backslashes before the pluses when it reaches the second stage. So the
backslashes have to pass intact through the first stage. Thus, they have to
be escaped themselves...

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herouth/personal/



Re: [GENERAL] Quoting/Escaping

From
Peter Eisentraut
Date:
On 1999-11-28, Bill Sneed mentioned:

> I'd like to be able to find a book title that contain C++ in the
> title....
>
> select * from books where title ~* 'C++'   doesn't work.
>
> I've tried all the basic methods of quoting the Plus (+) signs but
> none seem to work...

select * from books where title ~[*] 'C\\+\\+'

The reason seems to be that the parser *and* the regexp routine do their
thing with unquoting.

--
Peter Eisentraut                  Sernanders väg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden