[MDEV-31993] Wrong length of umlaut character Created: 2023-08-23  Updated: 2023-08-24  Resolved: 2023-08-23

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Georg Tsakumagos Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

10.6.12-MariaDB-0ubuntu0.22.04.1



 Description   

Character length should be equal.

Key Value
charset utf8mb4
collation utf8mb4_german2_ci
statement select LENGTH ("ä"), LENGTH ("a") from dual;
result 2, 1
expect 1, 1


 Comments   
Comment by Sergei Golubchik [ 2023-08-23 ]

LENGTH() returns the length in bytes: https://mariadb.com/kb/en/length/
If you want the length in characters, use CHAR_LENGTH():

MariaDB [test]> select LENGTH ("ä"), LENGTH ("a") from dual;
+---------------+--------------+
| LENGTH ("ä")  | LENGTH ("a") |
+---------------+--------------+
|             2 |            1 |
+---------------+--------------+
1 row in set (0.001 sec)
 
MariaDB [test]> select CHAR_LENGTH ("ä"), CHAR_LENGTH ("a") from dual;
+--------------------+-------------------+
| CHAR_LENGTH ("ä")  | CHAR_LENGTH ("a") |
+--------------------+-------------------+
|                  1 |                 1 |
+--------------------+-------------------+
1 row in set (0.001 sec)

Comment by Georg Tsakumagos [ 2023-08-24 ]

For those searching a solution and dislike to change their clients:

SET SQL_MODE='ORACLE';
select LENGTH ('ä'), LENGTH ('a') from dual;
 
LENGTH ('ä')|LENGTH ('a')|
------------+------------+
           1|           1|

The mode could be set also in server config.
https://mariadb.com/kb/en/sql_modeoracle/#functions

[mysqld]
sql_mode="ORACLE"

Generated at Thu Feb 08 10:28:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.