Help Center/ GaussDB/ Distributed_8.x/ SQL Reference/ Character Sets and Collations/ Character Sets and Collations of Expressions of the String Type
Updated on 2024-06-03 GMT+08:00

Character Sets and Collations of Expressions of the String Type

Each expression of the string type contains character sets and collation attributes.

In MySQL-compatible mode (sql_compatibility is set to 'MYSQL'), if b_format_version is set to '5.7' and b_format_dev_version is set to 's2', the default character sets and collations of string constants are determined by the system parameters character_set_connection and collation_connection. Otherwise, the default character set is the same as server_encoding of the database, and the default collation is default.

Character set syntax:

GaussDB does not support the character set of string constants specified by the following syntax:

1
[_charset_name]'string'

Collation syntax:

You can also specify the collation for expressions of other character string types.

1
EXPRESSION [COLLATE collation_name]

Parameters:

COLLATE collation_name

Collation name, which is the collation attribute of the string.

  • The data type of the expression must be a data type that supports collations.
  • The specified collation must be supported by the character set of the expression.

Example:

1
2
-- Use the COLLATE statement to specify the collation.
gaussdb=# SELECT 'a' COLLATE utf8mb4_general_ci = 'A';