Postgresql 模式匹配数字的字符串列

编程入门 行业动态 更新时间:2024-10-06 20:32:35
本文介绍了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 模式匹配数字的字符串列

本文发布于:2023-10-19 01:44:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1506024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:串列   字符   模式   数字   Postgresql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!