text & char(32)

Поиск
Список
Период
Сортировка
Искать

text & char(32)

От:
"Vladimir V. Zolotych" <gsmith@eurocom.od.ua>
Дата:
  Hi all,
Can you help me a bit ?
The question is: how can I compare TEXT and CHAR(32) types ?
More detailed description:
  my=> create table foo (tt text, cc char(32));

  CREATE
  my=> insert into foo values ('aa', 'ab');

  INSERT 27476810 1
  my=> insert into foo values ('aa', 'aa');

  INSERT 27476811 1
  my=> select * from foo where tt=cc;

  tt|cc
  --+--
  (0 rows)
So the operator '=' doesn't work as I expected.
Any help will be appreciated.

-- 
Best regards,
 Vladimir                          mailto:gsmith@eurocom.od.ua


Re: text & char(32)

От:
Herbert Ambos <herbert@hindang.msuiit.edu.ph>
Дата:
On Tue, 19 Sep 2000, Vladimir V. Zolotych wrote:

>   Hi all,
> Can you help me a bit ?
> The question is: how can I compare TEXT and CHAR(32) types ?
> More detailed description:
>   my=> create table foo (tt text, cc char(32));
> 
>   CREATE
>   my=> insert into foo values ('aa', 'ab');
> 
>   INSERT 27476810 1
>   my=> insert into foo values ('aa', 'aa');
> 
>   INSERT 27476811 1
>   my=> select * from foo where tt=cc;
> 
>   tt|cc
>   --+--
>   (0 rows)
> So the operator '=' doesn't work as I expected.
> Any help will be appreciated.
> 
> 

try

	select * from foo where tt=trim(cc);



herbert

Re: text & char(32)

От:
Karel Zak <zakkr@zf.jcu.cz>
Дата:

On Tue, 19 Sep 2000, Vladimir V. Zolotych wrote:

>   Hi all,
> Can you help me a bit ?
> The question is: how can I compare TEXT and CHAR(32) types ?
> More detailed description:
>   my=> create table foo (tt text, cc char(32));
> 
>   CREATE
>   my=> insert into foo values ('aa', 'ab');
> 
>   INSERT 27476810 1
>   my=> insert into foo values ('aa', 'aa');
> 
>   INSERT 27476811 1
>   my=> select * from foo where tt=cc;
> 
>   tt|cc
>   --+--
>   (0 rows)

 Because you not compare 'aa' and 'aa' but

	'aa' and 'aa                    '
                  ^^^^^^^^^^^^^^^^^^^^^^
			   32 chars

 try:

 test=# select * from foo where tt::char = cc;
 tt |                cc
----+----------------------------------
 aa | aa
(1 row)

 Better is use varchar(32) for 'cc' if you want run this (tt=cc) query 
often.
  
				Karel

Re: text & char(32)

От:
bangh <banghe@baileylink.net>
Дата:
If your define your table using varchar(32), instead of char(32), your
query will work fine.


--
banghe

Herbert Ambos wrote:

> On Tue, 19 Sep 2000, Vladimir V. Zolotych wrote:
>
> >   Hi all,
> > Can you help me a bit ?
> > The question is: how can I compare TEXT and CHAR(32) types ?
> > More detailed description:
> >   my=> create table foo (tt text, cc char(32));
> >
> >   CREATE
> >   my=> insert into foo values ('aa', 'ab');
> >
> >   INSERT 27476810 1
> >   my=> insert into foo values ('aa', 'aa');
> >
> >   INSERT 27476811 1
> >   my=> select * from foo where tt=cc;
> >
> >   tt|cc
> >   --+--
> >   (0 rows)
> > So the operator '=' doesn't work as I expected.
> > Any help will be appreciated.
> >
> >
>
> try
>
>         select * from foo where tt=trim(cc);
>
> herbert

FAQ