New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid result of comparing of the same character in different cases (upper/lower) [CORE6194] #6439
Comments
Modified by: Vladimir Lomov (l_vv)description: Maybe I misunderstand something, but it seems that comparing the same character in different cases does not work correctly. Test case: select ascii_val('Z') as Z_Upper, -- = 90 => Maybe I misunderstand something, but it seems that comparing the same character in different cases does not work correctly. Test case: select ascii_val('Z') as Z_Upper, -- = 90 Database creation script: CREATE DATABASE 'Test.db' commit; |
Modified by: Vladimir Lomov (l_vv)description: Maybe I misunderstand something, but it seems that comparing the same character in different cases does not work correctly. Test case: select ascii_val('Z') as Z_Upper, -- = 90 Database creation script: CREATE DATABASE 'Test.db' commit; => Maybe I misunderstand something, but it seems that comparing the same character in different cases does not work correctly. Test case: select ascii_val('Z') as Z_Upper, -- = 90 Database creation script: CREATE DATABASE 'Test.db' commit; Should COLLATION UNICODE_CI_AI affect the comparison of characters in different registers, or only sorting order? |
Commented by: @AlexPeshkoff Did not reproduce. Z_UPPER Z_LOWER Z_UPPER_NUM Z_LOWER_NUM CHAR_COMPARE ASCII_CHAR_COMPARE (i.e. as expected). |
Commented by: Vladimir Lomov (l_vv) Just run this test, will attach screentshot below: isql -quiet -bail -input test.sql Contents of test.sql: SET NAMES UTF8; connect localhost:Test.db user XXX password YYY ROLE DB_OWNER; SET SQL DIALECT 3; select ascii_val('Z') as Z_Upper, -- = 90 commit; exit; |
Commented by: Vladimir Lomov (l_vv) Sorry, can't attach screenshot. Paste text output of isql: Y:\home\data\projects\Test\sql\01_firebird\02_tables_create>99_test.bat Active code page: 1251 21.11.2019 17:50:12 Executing test.sql... Z_UPPER Z_LOWER Z_UPPER_NUM Z_LOWER_NUM CHAR_COMPARE ASCII_CHAR_COMPARE ======= ======= =========== =========== ============ ================== 90 122 Z z 1 2 21.11.2019 17:50:13 Done Active code page: 866 |
Commented by: @AlexPeshkoff With |
Commented by: @asfernandes Your literals uses UNICODE_CI_AI (case insensitive), while ASCII_CHAR returns data in ASCII charset/collation (case sensitive) internally in the engine, as conversion to connection charset only happens when data is going to client. So, there is no bug. |
Commented by: @hvlad Vladimir, > Should COLLATION UNICODE_CI_AI affect the comparison of characters in different registers, or only sorting order? From SQL Standard: ---------------- a) Syntax Rules of Subclause 9.13, "Collation determination", are applied with the declared types of the b) If the length in characters of X is not equal to the length in characters of Y, then the shorter string is c) The result of the comparison of X and Y is given by the collation CS. d) Depending on the collation, two strings may compare as equal even if they are of different lengths or You see - strings comparison is affected by collation |
Commented by: Vladimir Lomov (l_vv) But what then, if in select you need sort row case-insensitive, but in PSQL you need compare data from same columns case-sensitive? And perhaps this should be clarified in the documentation? The Language Reference for version 2.5 (in English) does not say what COLLATION specifically applies to - only to sort order, or to compare characters, too: 1. Firebird 2.5 Language Reference (English), page 22 UNICODE_CI_AI Case-insensitive, accent-insensitive collation, works alphabetically without taking 2. The Language Reference for version 4.0 (in Russian) says that COLLATION applies to sort order: Firebird 4.0 Beta 2 DBMS SQL Language Reference, page 52 |
Commented by: Sean Leyne (seanleyne) Based on comments from Adriano and Vlad, there is no issue to be resolved. |
Modified by: Sean Leyne (seanleyne)status: Open [ 1 ] => Resolved [ 5 ] resolution: Won't Fix [ 2 ] |
Modified by: @pcisarstatus: Resolved [ 5 ] => Closed [ 6 ] |
Submitted by: Vladimir Lomov (l_vv)
Maybe I misunderstand something, but it seems that comparing the same character in different cases does not work correctly.
The same example works OK in Oracle.
Test case:
select ascii_val('Z') as Z_Upper, -- = 90
ascii_val('z') as Z_Lower, -- = 122
ascii_char(90) as Z_Upper_num, -- = 'Z'
ascii_char(122) as Z_Lower_num, -- = 'z'
case
when 'Z' = 'z' then 1 -- Why do we get here?
else 2
end as char_compare,
case
when ascii_char(90) = ascii_char(122) then 1
else 2 -- We are here, it is correct
end as ascii_char_compare
from rdb$database;
Database creation script:
SET SQL DIALECT 3;
CREATE DATABASE 'Test.db'
USER SYSDBA
PAGE_SIZE 16384 DEFAULT CHARACTER SET UTF8 COLLATION UNICODE_CI_AI;
commit;
Should COLLATION UNICODE_CI_AI affect the comparison of characters in different registers, or only sorting order?
The text was updated successfully, but these errors were encountered: