Difference in text/char data matching between 7.3.4 & 7.4.2

From: Kazuya Togashi <togashi(at)sra(dot)co(dot)jp>
To: pgsql-general(at)postgresql(dot)org
Subject: Difference in text/char data matching between 7.3.4 & 7.4.2
Date: 2004-07-05 12:21:35
Message-ID: 40E947CF.6050000@sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I have a question regarding to text/char data matching difference
between PostgreSQL version 7.3.4 and 7.4.2, and would like to have your
variable opinions on this issue.

With version 7.3.4, following query returns true, but with version 7.4.2
it returns false.

select ' '::text = ' '::char;

Following query works fine (returns true) with both versions:

select ' '::text = ' '::varchar;

Further I checked the difference in text/char data matching between
7.3.4 and 7.4.2, and here is what I did:

1) Create Test Table
create table test(text_col text, char_col char(1), varchar_col varchar(1));

2) Insert Test Data
insert into test (text_col, char_col, varchar_col) values (' ',' ',' ');

3) Issued Following 3 Queries
select count(*) from test where text_col = char_col;
select count(*) from test where text_col = varchar_col;
select count(*) from test where varchar_col = char_col;

4) Compare the Results of both 7.3.4 and 7.4.2

======================
The Result with 7.3.4
======================
# create table test(text_col text, char_col char(1), varchar_col
varchar(1));
CREATE TABLE
# insert into test (text_col, char_col, varchar_col) values (' ',' ',' ');
INSERT 1253317 1
# select count(*) from test where text_col = char_col;
count
-------
1
(1 row)

# select count(*) from test where text_col = varchar_col;
count
-------
1
(1 row)

# select count(*) from test where varchar_col = char_col;
ERROR: Unable to identify an operator '=' for types 'character varying'
and 'character'
You will have to retype this query using an explicit cast

======================
The Result with 7.4.2
======================
# create table test(text_col text, char_col char(1), varchar_col
varchar(1));
CREATE TABLE
# insert into test (text_col, char_col, varchar_col) values (' ',' ',' ');
INSERT 784823 1
# select count(*) from test where text_col = char_col;
count
-------
0 => with 7.3.4, it returns "1".
(1 row)

# select count(*) from test where text_col = varchar_col;
count
-------
1
(1 row)

# select count(*) from test where varchar_col = char_col;
count
-------
1 => with 7.3.4, this query triggers an error.
(1 row)

I would like to know if this is a bug or something should be fixed. If
not, I guess I have to always do casting?

Any opinion is appreciated.

Thanks,
Kazuya

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Franco Bruno Borghesi 2004-07-05 13:20:07 Re: Formatting Function..
Previous Message Najib Abi Fadel 2004-07-05 12:18:12 Re: Bug in function to_char() !!