如果我运行此查询:
SELECT 'Via Orologio 122 A' SIMILAR TO '(Strada|Via) % [0-9]+( [A-Z])?';
我希望得到真实. postgresql版本9.1.8返回预期值,但在版本8.3中它返回FALSE.我认为问题是最后一个问号.实际上,查询:
SELECT 'Via Orologio 122 A' SIMILAR TO '(Strada|Via) % [0-9]+( [A-Z])';
两个版本都返回TRUE.
谁知道这两个版本有什么区别?
解决方法
从
changelog of 8.3.2开始:
Fix a corner case in regular-expression substring matching
(substring(string from pattern))
(Tom)
The problem occurs when there
is a match to the pattern overall but the user has specified a
parenthesized subexpression and that subexpression hasn’t got a match.
An example issubstring('foo' from 'foo(bar)?')
. This should return
NULL,since(bar)
isn’t matched,but it was mistakenly returning the
whole-pattern match instead (ie,foo
)