本文介绍了Postgresql 模式匹配数字的字符串列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个字符串形式的测量表(即4.6 英寸、3 毫米"、长度:4.66 英寸"等),我想检索包含数字左边或右边任何内容的行,只要号码匹配.
Given a table of measurements as strings (i.e. "4.6 Inches, 3mm", "Length: 4.66in", etc), I'd like to retrieve rows with essentially anything left or right of the number, so long as the number matches.
换句话说,如果我要搜索6":
In other words, if I'm searching for "6":
- 匹配:6 in"、6in"、asdf 6 in"等
- 不匹配:16 in"、6.6 in"、with 66 in"等
到目前为止,我有以下查询:
I have the following query thus far:
select distinct length from items where length ~ '[[:<:]]6[[:>:]]';但这不是我想要的,因为这是结果:
But it's not quite what I'm looking for, as this is the result:
length --------------- 6.25 Inches 4.6666 Inches 6.5 Inches 1.66 Inches 6 Inches 6.75 Inches 6.71 Inches 24.6 Inches 3.6666 Inches我正在使用 PostgreSQL 9.任何帮助将不胜感激.谢谢
I'm using PostgreSQL 9. Any help would be appreciated. Thanks
推荐答案怎么样 :
'^[^0-9]*6[^0-9]*$'更多推荐
Postgresql 模式匹配数字的字符串列
发布评论