如果 regexp_match 失败,Select 空列

Select empty column if regexp_match fails

我正在尝试 select 所有实体,即使它们不匹配表达式,但这个 returns 仅 'true' 个值。

SELECT entity_id, regexp_matches(error_params, '"select_flight"') IS NOT NULL
FROM MyTable
GROUP BY 1

有没有办法在 SELECT 语句中解决此类问题,或者在这种情况下我们应该使用 LEFT JOIN 到 table 和 regexp_matches 结果?

如果我没有正确理解你的问题,你可以使用 countcase:

select entity_id,
       count(case when error_params like '%select flight%' then 1 end) cnt
from mytable
group by 1