- OS: Windows 10
- Docker OS: Alpine Linux 3.18.3
- DB: PostgreSQL 15
I created a new PostgreSQL database named test1 with zh-x-icu as the default collation using the following command:
postgres=> create database test1 with encoding 'UTF8' owner db_owner lc_collate 'zh-x-icu' lc_ctype 'zh-x-icu' template template0;
When I list the databases, the datcollate and datctype columns show the expected values:
| datname | datdba | encoding | datcollate | datctype |
|---|---|---|---|---|
| template1 | 10 | 6 | en_US.utf8 | en_US.utf8 |
| template0 | 10 | 6 | en_US.utf8 | en_US.utf8 |
| postgres | 10 | 6 | en_US.utf8 | en_US.utf8 |
| test1 | 43170 | 6 | zh-x-icu | zh-x-icu |
However, when I run queries in this database, the sorting behavior doesn't align with the default collation zh-x-icu. Here are some examples:
| query | result |
|---|---|
| SELECT * FROM (VALUES ('张'), ('李'), ('王'), ('赵'), ('刘')) AS names(name) ORDER BY name; | 刘张李王赵 |
| SELECT * FROM (VALUES ('张'), ('李'), ('王'), ('赵'), ('刘')) AS names(name) ORDER BY name collate "en-x-icu"; | 刘张李王赵 |
| SELECT * FROM (VALUES ('张'), ('李'), ('王'), ('赵'), ('刘')) AS names(name) ORDER BY name collate "zh-x-icu"; | 李刘王张赵 |
As you can see, the query without explicit collation returns the same result as the one with 'en-x-icu', which is not what I expected. I expected it to behave like the 'zh-x-icu' query since that's the default collation for the database.
Why is this happening, and how can I make the default collation apply to queries in this database?
Here is the docker-compose:
version: '3'
services:
timescaledb:
image: timescale/timescaledb:latest-pg15
hostname: d16f59bcb903
mac_address: 02:42:ac:11:00:02
environment:
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- LANG=en_US.utf8
- PG_MAJOR=15
- PG_VERSION=15.4
- PG_SHA256=baec5a4bdc4437336653b6cb5d9ed89be5bd5c0c58b94e0becee0a999e63c8f9
- DOCKER_PG_LLVM_DEPS=llvm15-dev clang15
- PGDATA=/var/lib/postgresql/data
volumes:
- H:\DB_PG15:/var/lib/postgresql/data
- /var/lib/postgresql/data
ports:
- "5432:5432"
restart: "no"
labels:
maintainer: "Timescale https://www.timescale.com"
runtime: runc