【发布时间】:2020-07-16 21:56:52
【问题描述】:
我有一个用于地址的数据库 (Postgres 7.4) 字段
示例数据
address | zip
-----------------------+-------------+
123 main street | 12345
-----------------------+-------------+
3 where road | 12345
-----------------------+-------------+
South 3 where road | 12345
查询
SELECT *
FROM tbl
WHERE zip = 12345
AND address ILIKE '3%'
我得到了所有,但我不想要 123 大街
SELECT *
FROM tbl
WHERE zip = 12345
AND address ILIKE '123%'
我得到了我想要的结果
我的问题是如何匹配地址的数字部分?
【问题讨论】:
-
postgre 是否支持
REGEX?我知道 MySQL 可以,但我不太确定 postgre。 -
是的,但这是 Postgres 的旧版本,所以我会受到限制 postgresql.org/docs/7.4/static/functions-matching.html
-
感谢您的澄清。我不太确定。只是一个想法——如果你只是想匹配一个固定的数字,为什么不做第二个查询呢?还是您在寻找开头有(出)数字的行?
-
另外,考虑升级到更新的版本。 7.4 是古老的。
-
@Polynomial:不是no such thing as "postgre"。
标签: sql postgresql split numeric