Hmm. I had also tried with "code" as a VARCHAR and it worked properly on my
system.
business=> create table foo ( mytext varchar(10) );
CREATE
business=> insert into foo values ( '4' );
INSERT 120521 1
business=> insert into foo values ( '(4)' );
INSERT 120522 1
business=> select * from foo;
mytext
------
4
(4)
(2 rows)
business=> select * from foo where mytext like '(4)';
mytext
------
(4)
(1 row)
I just noticed, though, that I tested this on version 6.5.0. It is
conceivable that something has changed between my version and 6.5.3.
Are you running your queries through psql? Also, is it possible that there
are leading characters in the data?
Phil Culberson
DAT Services
-----Original Message-----
From: Gabriel Fernandez [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 21, 2000 7:31 AM
To: Culberson, Philip
Subject: Re: [GENERAL] Problem with LIKE operator
Hi Philip,
First of all, thanks a lot for your quick response philip, but this is not
the problem.
The column is a varchar, and the '(4)%' trick doesn't work. I guess is
something related to the fact that maybe in PostgreSql, the bracket is
something you can use within the syntax of the LIKE operator (as in regular
expressions). Or maybe the LIKE operator is not working Ok in my server
(i'm using 6.5.3 on Red Hat 6.0).
Do you know something about it ?
Gabi :-)
"Culberson, Philip" wrote:
> Gabriel,
>
> If you defined column "code" as a CHAR(n), you will need to have a "%"
> wildcard at the end of your search string to allow for padding.
>
> select code from codes where code like '(4)%' ;
>
> Example:
> business=> create table foo ( mytext char(10) );
> CREATE
> business=> insert into foo values ('4');
> INSERT 120479 1
> business=> insert into foo values ('(4)');
> INSERT 120480 1
> business=> select * from foo;
> mytext
> ----------
> 4
> (4)
> (2 rows)
>
> business=> select * from foo where mytext like '(4)';
> mytext
> ------
> (0 rows)
>
> business=> select * from foo where mytext like '(4)%';
> mytext
> ----------
> (4)
> (1 row)
>
> Phil Culberson
> DAT Services
>
> -----Original Message-----
> From: Gabriel Fernandez [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 21, 2000 4:47 AM
> To: PostgreSQL-general
> Subject: [GENERAL] Problem with LIKE operator
>
> Hi,
>
> I have some problems using LIKE within strings which have brackets.
>
> For example if i do:
>
> select code from codes where code like '(4)' ;
>
> i do not obtain nothing. But in the DB indeed there is a row whose code
> is '(4)'.
>
> I have tried to escape the brackets with '\\(4\\)' or with ' \(4\)' but
> it doesn't work.
>
> How can i do it ?
>
> Gabi :-)