SORT_COLLATION option

Function

Allows implicit use of the SORTKEY function on ORDER BY expressions.

Allowed values

Internal, collation_name, or collation_id

Default

Internal

Scope

DBA permissions are not required to set this option. Can be set temporary for an individual connection or for the PUBLIC group. Takes effect immediately.

Description

When the value of this option is Internal, the ORDER BY clause remains unchanged.

When the value of this option is set to a valid collation name or collation ID, any string expression in the ORDER BY clause is treated as if the SORTKEY function has been invoked.

Example

Set the sort collation to binary:

SET TEMPORARY OPTION sort_collation='binary';

Setting the sort collation to binary transforms these queries:

SELECT Name, ID
FROM Products
ORDER BY Name, ID;
SELECT Name, ID
FROM Products
ORDER BY 1, 2;

The queries are transformed into:

SELECT Name, ID
FROM Products
ORDER BY SORTKEY(Name, 'binary'), ID;

See also

“SORTKEY function [String]” in Chapter 4, “SQL Functions” of Reference: Building Blocks, Tables, and Procedures