Postgresql 排序混合字母数字数据

标签 postgresql sorting alphanumeric

运行此查询:

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允许整理不可知排序的数据类型:

SELECT name
FROM folders
ORDER BY name::bytea;

结果:

     name     
--------------
 a test
 alphanumeric
 test 1
 test 10
 test 19
 test 20
(6 rows)

关于Postgresql 排序混合字母数字数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7018628/

相关文章:

algorithm - 所有类别的线性时间排序

jquery 数据表 : update table cell after button click

Python将字母数字字符串列表插入数据库

validation - 如何在 VBScript 中检查字符串是否为字母数字?

通过终端连接 Postgresql - pgadmin

java - Postgresql 与 Hibernate : could not determine LocalDate type in jpql query

SQL 查询将分组结果作为单行返回

python - 在 python 中使用 SQLAlchemy 将行迭代地插入到 postgreSQL 数据库中

mongodb - 在 Mongodb 中,我如何首先按分数排序,如果有 "tie"则按时间排序?

php - 删除空格和任何非字母数字的内容