gpt4 book ai didi

sql - 忽略 ORDER BY 子句中的引号、数字、空格等

转载 作者:行者123 更新时间:2023-11-29 14:19:46 25 4
gpt4 key购买 nike

我使用 ORDER BY title ASC 按标题对产品进行排序,并得到:

"Some" title       // "
1 More title // 1
Another title // A
Third title // T
Yet another title // Y

我想在查询中忽略引号和其他非字母字符,这样它会产生:

Another title      // A
1 More title // M
"Some" title // S
Third title // T
Yet another title // Y

是否可以使用 Postgres 去除这些内容或将其作为查询的一部分进行预处理,或者我是否需要另一列?

更新

效果很好:LOWER(regexp_replace(title, '[^[:alpha:]]', '', 'g')) ASC

此处提供更多选项:http://www.postgresql.org/docs/current/interactive/functions-matching.html#POSIX-CLASS-SHORTHAND-ESCAPES-TABLE

最佳答案

一种方法是使用regexp_replace():

order by regexp_replace(title, '[^a-zA-Z]', '', 'g')

您还可以使用:

order by regexp_replace(title, '[^[:alpha:]]', '', 'g')

这对于非 ASCII 字符集更安全。

关于sql - 忽略 ORDER BY 子句中的引号、数字、空格等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33398412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com