设置Order By以忽略每个列的标点符号 [英] Set Order By to ignore punctuation on a per-column basis
问题描述
是否可以通过标题字段对PostgreSQL查询的结果进行排序,该标题字段包含 [](),;
等字符,但忽略这些标点符号和
Is it possible to order the results of a PostgreSQL query by a title field that contains characters like [](),;
etc but do so ignoring these punctuation characters and sorting only by the text characters?
我已经阅读了有关更改数据库排序规则或语言环境的文章,但尚未找到有关如何在现有数据库上执行此操作的明确说明每个列。
I've read articles on changing the database collation or locale but have not found any clear instructions on how to do this on an existing database an on a per-column basis. Is this even possible?
推荐答案
如果要在一个特定查询中进行此排序,可以
If you want to have this ordering in one particular query you can
ORDER BY regexp_replace(title, '[^a-zA-Z]', '', 'g')
它将根据结果字段从字符串和顺序中删除所有非 AZ
。
It will delete all non A-Z
from sting and order by resulting field.
这篇关于设置Order By以忽略每个列的标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!