I've been getting a funny SQL error, which I've boiled down to this case.
SELECT (regexp_matches('abc', '(.)b(.)'))[1] IS NOT NULL
-- Returns true, as expected
SELECT (regexp_matches('abc', '(.)b(.)'))[1] IS NOT NULL AND true
-- Gives this error:
ERROR: argument of AND must not return a set
SQL state: 42804
Can anyone make heads or tails of it? Is it a real bug? Is there a work around?
Postgres 8.3
Robert James <srobertjames@gmail.com> writes:
> SELECT (regexp_matches('abc', '(.)b(.)'))[1] IS NOT NULL AND true
> -- Gives this error:
> ERROR: argument of AND must not return a set
> SQL state: 42804
> Can anyone make heads or tails of it? Is it a real bug? Is there a work around?
It's not a bug: regexp_matches returns a set of rows, not a scalar
result.
You might want to stick it into a sub-select as per the trick suggested
in the manual - then you get a NULL rather than zero rows when there's
no match. (Or, in the particular example at hand, it's not very clear
why you're using regexp_matches at all and not a plain old ~ operator.)
regards, tom lane
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера