设置Order By以忽略每个列的标点符号 [英] Set Order By to ignore punctuation on a per-column basis

查看:114
本文介绍了设置Order By以忽略每个列的标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过标题字段对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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆