PostgreSQL排序混合的字母数字数据 [英] Postgresql sorting mixed alphanumeric data
本文介绍了PostgreSQL排序混合的字母数字数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行此查询:
select name from folders order by name
返回以下结果:
alphanumeric
a test
test 20
test 19
test 1
test 10
但是我期望:
a test
alphanumeric
test 1
test 10
test 19
test 20
这里出了什么问题?
推荐答案
您只需将 name
列强制转换为 bytea
数据类型,允许与整理无关的排序:
You can simply cast name
column to bytea
data type allowing collate-agnostic ordering:
SELECT name
FROM folders
ORDER BY name::bytea;
结果:
name
--------------
a test
alphanumeric
test 1
test 10
test 19
test 20
(6 rows)
这篇关于PostgreSQL排序混合的字母数字数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文