开发者

How to work with first item of array?

开发者 https://www.devze.com 2023-03-04 17:28 出处:网络
SELECT regexp_matches(\'abc\', \'[0-9]*\'); The query above returns text[] and need to check, whether it found any (i don\'t care which) matches or none.

SELECT regexp_matches('abc', '[0-9]*');

The query above returns text[] and need to check, whether it found any (i don't care which) matches or none.

So in case above i get {""}, how can i get "boolean" value, which tells me if it matches something or nothing?

This seems not work:

SELECT regexp_matches('abc', '[0-9]*') = '{}';

开发者_StackOverflow社区


Use the ~ operator:

SELECT 'abc' ~ '[0-9]*';

Alternatively, you could pull out the first item like this:

SELECT (regexp_matches('abc', '[0-9]*'))[1] = ''; -- True if it didn't match

Note the extra parentheses and that the array is indexed starting at 1.

0

精彩评论

暂无评论...
验证码 换一张
取 消