使用 order by convert_to(city, ‘GBK’) 方式按中文字典顺序排序, 测试如下:
create table public.test_city(id bigserial primary key, city char(10));test#\d jinbo.test_city;Table "public.test_city"Column |Type|Modifiers --------+---------------+--------------------------------------------------------------id| bigint | not null default nextval('public.test_city_id_seq'::regclass)city | character(10) | Indexes:"test_city_pkey" PRIMARY KEY, btree (id)test=# insert INTO public.test_city(city) values ('上海'),('北京'),('广州');INSERT 0 3test=# insert INTO public.test_city(city) values ('西安'),('榆林'),('三亚');INSERT 0 3test=# insert INTO public.test_city(city) values ('深圳'),('鞍山'),('昆明');INSERT 0 3test=# insert INTO public.test_city(city) values ('大连'),('青岛'),('成都');INSERT 0 3test=# select * from public.test_city;id |city----+--------------1 | 上海 2 | 北京 3 | 广州 4 | 西安 5 | 榆林 6 | 三亚 7 | 深圳 8 | 鞍山 9 | 昆明 10 | 大连 11 | 青岛 12 | 成都 (12 rows)test=# select * from public.test_city order by convert_to(city, 'GBK');id |city----+--------------8 | 鞍山 2 | 北京 12 | 成都 10 | 大连 3 | 广州 9 | 昆明 11 | 青岛 6 | 三亚 1 | 上海 7 | 深圳 4 | 西安 5 | 榆林 (12 rows)