【发布时间】:2018-09-05 06:52:10
【问题描述】:
我有一个name 列,如下所示:
'1234567 - 7654321 - some - more - text'
我需要得到一个字符串"7654321"。我坚持以下几点:
SELECT regexp_matches('1234567 - 7654321 - some - more - text', '\d+', 'g');
regexp_matches
----------------
{1234567}
{7654321}
(2 rows)
我怎么做我想要的?也许有比regexp_matches 更好的选择 - 很乐意考虑。谢谢!
【问题讨论】:
-
试试
SELECT regexp_matches('1234567 - 7654321 - some - more - text', '-\s*(\d+) -'); -
@WiktorStribiżew 好一个!但返回一个数组
-
SELECT substring('1234567 - 7654321 - some - more - text', '- (\d+) -');呢? -
@WiktorStribiżew 这在控制台中有效,但是当我尝试将其用于我需要的内容(设置新列的值)时,它无法设置为 null
标签: sql regex postgresql