Show TOC

SORT_COLLATION OptionLocate this document in the navigation structure

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

Allowed Values

Internal, collation_name, or collation_id

Default

Internal

Scope

Option can be set at the database (PUBLIC) or user level. At the database level, the value becomes the default for any new user, but has no impact on existing users. At the user level, overrides the PUBLIC value for that user only. No system privilege is required to set option for self. System privilege is required to set at database level or at user level for any user other than self.

Requires the SET ANY PUBLIC OPTION system privilege to set this option. Can be set temporary for an individual connection or for the PUBLIC role. Takes effect immediately.

Remarks

When the value of SORT_COLLATION 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.

Functions are described in Reference: Building Blocks, Tables, and Procedures.

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;