PostgreSQL下,对汉字按拼音排序

参考学习此文:

http://blog.163.com/digoal@126/blog/static/163877040201173003547236/

建库

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=# 

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值