[MDEV-25131] using COLLATE utf8mb4_unicode_ci with GENERATED column throws error but works in mysql Created: 2021-03-14  Updated: 2021-04-05

Status: Open
Project: MariaDB Server
Component/s: Data Definition - Create Table
Affects Version/s: 10.5.8
Fix Version/s: 10.5

Type: Bug Priority: Major
Reporter: ahmed sayed abdelsalam Assignee: Alexey Botchkov
Resolution: Unresolved Votes: 0
Labels: None
Environment:

macOs


Issue Links:
Relates
relates to MDEV-14301 JSON_UNQUOTE returns incorrect result... Stalled

 Description   

ERROR 1064 (42000) at line 539: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'GENERATED ALWAYS AS (json_unquote(json_extract(`name`,'$.en'))) VIRTUAL,



 Comments   
Comment by Alice Sherepa [ 2021-03-15 ]

it looks like MariaDB asks for an extra pair of parentheses + there is smth with json_unquote (MDEV-14301)

MariaDB [test]> create table t1 (name varchar(30), n1 varchar(30) GENERATED ALWAYS AS (json_unquote(json_extract(`name`,'$.en'))) virtual)  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Query OK, 0 rows affected (0.049 sec)
 
MariaDB [test]> show create table t1;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                               |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `name` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `n1` varchar(30) COLLATE utf8mb4_unicode_ci GENERATED ALWAYS AS (json_unquote(json_extract(`name`,'$.en'))) VIRTUAL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.004 sec)
 
MariaDB [test]> set names 'utf8mb4' collate utf8mb4_unicode_ci;
Query OK, 0 rows affected (0.001 sec)
 
MariaDB [test]> create table t2 (name varchar(30), n1 varchar(30) GENERATED ALWAYS AS (json_unquote(json_extract(`name`,'$.en'))) COLLATE utf8mb4_unicode_ci);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'COLLATE utf8mb4_unicode_ci)' at line 1
 
MariaDB [test]> create table t2 (name varchar(30), n1 varchar(30) GENERATED ALWAYS AS ((json_unquote(json_extract(`name`,'$.en'))) COLLATE utf8mb4_unicode_ci));
ERROR 1253 (42000): COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'utf8'
Error (Code 1253): COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'utf8'
Error (Code 4027): Got an error evaluating stored expression json_unquote(json_extract(`name`,'$.en')) collate utf8mb4_unicode_ci
MariaDB [test]> show variables like 'char%';
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | utf8mb4                          |
| character_set_connection | utf8mb4                          |
| character_set_database   | utf8mb4                          |
| character_set_filesystem | binary                           |
| character_set_results    | utf8mb4                          |
| character_set_server     | utf8mb4                          |
| character_set_system     | utf8                             |
| character_sets_dir       | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.007 sec)

Mysql 8.0.23:

mysql> create table t1 (name varchar(30), n1 varchar(30) GENERATED ALWAYS AS (json_unquote(json_extract(`name`,'$.en'))) COLLATE utf8mb4_unicode_ci);
Query OK, 0 rows affected (0.07 sec)
 
mysql> create table t2 (name varchar(30), n1 varchar(30) GENERATED ALWAYS AS (json_unquote(json_extract(`name`,'$.en')) COLLATE utf8mb4_unicode_ci));
Query OK, 0 rows affected (0.07 sec)

Generated at Thu Feb 08 09:35:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.