Specifying Character Set and Collation for Workspaces
On this page
Setting Character Set and Collation Engine Variables
You can specify the character set and collation for your workspace by setting the following engine variables.
-
character_
set_ server: The character set of the entire workspace that can be set to utf8mb4
,utf8
, orbinary
.If you set character_
to a value that is different from its previous value, SingleStore sets the associated collation variables collation_set_ server connection, collation_ database, and collation_ server to the character set’s default collation. To set the
character_
variable workspace-wide, follow the instructions below.set Warning
Although the
character_
variable is a session variable, you must set the variable globally to avoid undesired behavior.set_ server An error is generated if the variable is set in a session to a value that does not match the value set globally. Change the value globally first, then change it in the session to match. -
Using a SingleStore Helios client, run
SET CLUSTER
(which is the equivalent ofSET GLOBAL
) to set thecharacter_
variable across the workspace.set_ server For example: SET CLUSTER character_set_server = 'utf8';Query OK, 0 rows affected (0.03 sec)
Note: SingleStore offers alternative commands to set engine variables.
See Sync Variables for more information.
-
-
collation_
connection, collation_ database, and collation_ server: These are the collation variables that are set workspace-wide, or on all aggregator nodes or leaf nodes depending on how you set the engine variables. These variables can take the collations returned by the SHOW COLLATION
command as values.When you set any of collation_
,connection collation_
, anddatabase collation_
, SingleStore sets the other two variables to the same value and applies the collation to the nodes.server Also, when you set any of these three variables, SingleStore sets character_ set_ server to a value that corresponds to the collation configured. To set the collation variables workspace-wide, follow the instructions below.
Warning
Although the collation variables are session variables, you must set the variable globally to avoid undesired behavior.
An error is generated if any of these variables is set in a session to a value that does not match the value set globally. Change the value globally first, then change it in the session to match. -
Using a SingleStore Helios client, run
SET CLUSTER
(which is the equivalent of SET GLOBAL) to set the collation variable across the workspace.For example: SET CLUSTER collation_server = 'utf8_general_ci';Query OK, 0 rows affected (0.03 sec)
Note: SingleStore offers alternative commands to set engine variables.
See Sync Variables for more information.
-
To set a collation workspace-wide, issue the following command.
SET CLUSTER collation_server = 'utf8_general_ci';
Query OK, 0 rows affected (0.03 sec)
Alternatively, you can use SET AGGREGATOR
or SET LEAF
to sync the collation variable to the respective nodes.
Reading Character Set and Collation Engine Variables
To retrieve values of the character set or the collation in current use, use the @@
selector with the required variable in a SELECT
statement.
SELECT @@collation_server;
+--------------------+
| @@collation_server |
+--------------------+
| utf8mb4_general_ci |
+--------------------+
1 row in set (0.00 sec)
Collation Demonstration
The following example shows that utf8_
collation is case-insensitive.
SET collation_connection = 'utf8_general_ci';SELECT 'A' = 'a';
The following example shows that utf8_
collation is case-sensitive.
SET collation_connection = 'utf8_bin';SELECT 'A' = 'a';
Important
Among the collations supported for the utf8mb4
character set, utf8mb4_
is recommended for accurate comparison and sorting of characters, especially when using characters from non-English international languages.utf8mb4_
improves the performance of comparing and sorting operations, the results may not be precise when using certain language characters.
Last modified: August 29, 2024