Flo*_*ian 1 regex postgresql json substring
我有一个带有以下json的表字段"data":
[{"reason": "Other", "bla": 12345, "amount": "34.00", "moredata": [23, 22], "date": "2014-01-02T01:55:28.646364+00:00", "message": "Bla", "applied_to": "client"}]
Run Code Online (Sandbox Code Playgroud)
而且我只想获得金额的json值的值,所以在PostgreSQL中的情况下为34.00.
到目前为止,我有:
substring(data from '%#"_amount_: ___.___#"%' for '#'),
Run Code Online (Sandbox Code Playgroud)
可悲的是,这给了我"金额":"34.00",而不仅仅是34.00.如果金额值为9.00或102.00,它也不起作用.
任何帮助,将不胜感激.
尝试:
substring(data from '(?:"amount": ")([\d\.]*)')
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)NODE EXPLANATION -------------------------------------------------------------------- (?: group, but do not capture: -------------------------------------------------------------------- "amount": " '"amount": "' -------------------------------------------------------------------- ) end of grouping -------------------------------------------------------------------- ( group and capture to \1: -------------------------------------------------------------------- [\d\.]* any character of: digits (0-9), '\.' (0 or more times (matching the most amount possible)) -------------------------------------------------------------------- ) end of \1