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