码迷,mamicode.com
首页 > 数据库 > 详细

PostgreSQL对汉字按拼音排序

时间:2019-04-23 09:43:03      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:collate   pos   sci   ati   res   name   database   div   --   

转自:https://www.cnblogs.com/gaojian/p/3188609.html

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 db_utf8   | gao      | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 postgres  | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

postgres=#
postgres=# \d
               List of relations
 Schema |       Name        | Type  |  Owner   
--------+-------------------+-------+----------
 public | gao_chinese_order | table | postgres
 public | tbl_chinese_order | table | postgres
(2 rows)

postgres=#
insert into tbl_chinese_order values (‘刘少奇‘);

insert into tbl_chinese_order values (‘刘德华‘);

insert into tbl_chinese_order values (‘张学友‘);

普通排序

postgres=# select * from tbl_chinese_order order by info;
  info  
--------
 刘少奇
 刘德华
 张学友
(3 rows)
postgres=# select * from tbl_chinese_order order by convert_to(info,‘SQL_ASCII‘);
  info  
--------
 刘少奇
 刘德华
 张学友
(3 rows)

postgres=#

按拼音排序

postgres=# select * from tbl_chinese_order order by convert_to(info,‘GBK‘);
  info  
--------
 刘德华
 刘少奇
 张学友
(3 rows)

postgres=#
postgres=# select * from tbl_chinese_order order by convert_to(info,‘GB18030‘);
  info  
--------
 刘德华
 刘少奇
 张学友
(3 rows)

postgres=#

 

PostgreSQL对汉字按拼音排序

标签:collate   pos   sci   ati   res   name   database   div   --   

原文地址:https://www.cnblogs.com/sijizhen/p/10754274.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!