【发布时间】:2021-09-17 14:49:11
【问题描述】:
如何使用正则表达式在 redshift 中的两个子字符串之间提取某个值?
我在 redshift 的列中有如下字符串:
[{'code': 'bla', 'amount': '149.30', 'type': 'fixed_amount'}]
我想提取浮点数。 我使用了几个正则表达式,但似乎 redshift 不接受它们。
select order_id, discount_codes, regexp_substring(discount_codes, '''amount'': ''[^'']*') as value from orders_shopify_de
给我这个错误:
ERROR: function regexp_substring(character varying, "unknown") does not exist Hint
又例如:
regexp_replace(discount_codes, '(?<=''amount'': '')(.*)(?='',)')
给我这个错误:
ERROR: function regexp_substring(character varying, "unknown") does not exist Hint
有没有办法提取浮动?
提前致谢!
【问题讨论】:
-
REGEXP_SUBSTR(discount_codes, '''amount'': ''([^'']*)', 1, 1, 'e') -
@WiktorStribiżew 上帝保佑你:D 这行得通!我会尝试理解并适应它:)
标签: sql regex amazon-redshift