GassDB(DWS)功能 -- 中文排序
【摘要】 介绍一种在DWS中按照字段的中文拼音排序/大小写不敏感的排序方法
中文字段按照拼音排序
postgres=# CREATE TABLE public.dim_stu_pinyin_info (id bigint, name text) DISTRIBUTE BY REPLICATION;
CREATE TABLE
postgres=# INSERT INTO public.dim_stu_pinyin_info VALUES (1, '雷锋');
INSERT 0 1
postgres=# INSERT INTO public.dim_stu_pinyin_info VALUES (2, '石传祥');
INSERT 0 1
postgres=# SELECT * FROM public.dim_stu_pinyin_info
postgres-# ORDER BY NLSSORT (name, 'NLS_SORT = SCHINESE_PINYIN_M' );
id | name
----+--------
1 | 雷锋
2 | 石传祥
(2 rows)
postgres=# SELECT * FROM public.dim_stu_pinyin_info
postgres-# ORDER BY NLSSORT (name, 'NLS_SORT = SCHINESE_PINYIN_M' ) DESC;
id | name
----+--------
2 | 石传祥
1 | 雷锋
(2 rows)
大小写不敏感排序
postgres=# CREATE TABLE public.dim_stu_icase_info (id bigint, name text) DISTRIBUTE BY REPLICATION;
CREATE TABLE
postgres=# INSERT INTO public.dim_stu_icase_info VALUES (1, 'aaaa');
INSERT 0 1
postgres=# INSERT INTO public.dim_stu_icase_info VALUES (2, 'AAAA');
INSERT 0 1
postgres=# SELECT * FROM public.dim_stu_icase_info
postgres-# ORDER BY NLSSORT (name, 'NLS_SORT = generic_m_ci ' );
id | name
----+------
1 | aaaa
2 | AAAA
(2 rows)
postgres=# SELECT * FROM public.dim_stu_icase_info
postgres-# ORDER BY NLSSORT (name, 'NLS_SORT = generic_m_ci ' ) DESC;
id | name
----+------
1 | aaaa
2 | AAAA
(2 rows)
postgres=# SELECT * FROM public.dim_stu_icase_info
postgres-# ORDER BY name;
id | name
----+------
1 | aaaa
2 | AAAA
(2 rows)
postgres=# SELECT * FROM public.dim_stu_icase_info
postgres-# ORDER BY name DESC;
id | name
----+------
2 | AAAA
1 | aaaa
(2 rows)
postgres=#
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)