我有一个SQL
查询:
select
concat('PL', (regexp_matches( mt_line.info_to_owner, '(?<=~31)(.*?)(?=~)'))[1]) AS "sender",
(regexp_matches( mt_line.info_to_owner, '(?<=38)(.*?)(?=$)'))[1] AS "receiver"
from b.mt_line AS mt_line;
当我在本地数据库PostgreSQL版本9.6.12中执行它时,它工作正常,但在测试数据库-PostgreSQL 9.5.16版本中不起作用。
我在此出现以下错误:
[2201B] ERROR: invalid regular expression: quantifier operand invalid
如果我将此查询更改为:
select
concat('PL', (regexp_matches( mt_line.info_to_owner, '.*'))[1]) AS "sender",
(regexp_matches( mt_line.info_to_owner, '.*'))[1] AS "receiver"
from b.mt_line AS mt_line;
然后在两种版本的postgres上都能正常工作。
答案 0 :(得分:1)
lookbehind
是在postgres 9.6中引入的,请参见:
https://www.postgresql.org/docs/9.6/functions-matching.html
选中Table 9-17. Regular Expression Constraints
(?<=re) positive lookbehind matches at any point where a substring matching re ends (AREs only)
(?<!re) negative lookbehind matches at any point where no substring matching re ends (AREs only)
Postgres 9.5没有以下选项:https://www.postgresql.org/docs/9.5/functions-matching.html
校验
Table 9-15. Regular Expression Constraints
。