Thread: Operation eq with varchar

Operation eq with varchar

From
t.ngockhoi@bpf.vnu.com
Date:


HI ALL,

I don't no why i can't compare varchar with string const :

CREATE TABLE XXX (
     id   integer,
     stvarchar varchar
) ;


SELECT * FROM XXX WHERE stvarchar = 'somestring' ;

I can only use like operator :

SELECT * FROM XXX WHERE stvarchar like 'somestring%' ;

Any body know why ?

I have the 7.1.3 verion in redhat 7.2


Best Regards,
Ngoc-Khoi TO.




Re: Operation eq with varchar

From
Martijn van Oosterhout
Date:
On Thu, Dec 20, 2001 at 09:38:15AM +0100, t.ngockhoi@bpf.vnu.com wrote:
>
>
>
> HI ALL,
>
> I don't no why i can't compare varchar with string const :
>
> SELECT * FROM XXX WHERE stvarchar = 'somestring' ;

Does this work? (Untested)

SELECT * FROM XXX WHERE stvarchar = 'somestring'::varchar ;

HTH,
--
Martijn van Oosterhout <kleptog@svana.org>
http://svana.org/kleptog/
> Terrorists can only take my life. Only my government can take my freedom.

Re: Operation eq with varchar

From
Tom Lane
Date:
Perhaps you are forgetting to allow for trailing blanks in the stored
data?  Those are significant if you're using varchar.

            regards, tom lane

Re: Operation eq with varchar

From
"SHELTON,MICHAEL (Non-HP-Boise,ex1)"
Date:

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Thursday, December 20, 2001 8:02 AM
To: t.ngockhoi@bpf.vnu.com
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Operation eq with varchar


Perhaps you are forgetting to allow for trailing blanks in the stored
data?  Those are significant if you're using varchar.

            regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org