我在具有潛在NULL值的字段上使用ARRAY_AGG
,然後我想稍後檢查數組是否有空值。例如:ARRAY_AGG中的NULLS和檢查數組中的空值(Postgres 9.5.1)
WITH test AS
(
SELECT 'A' AS call_id, NULL AS outcome
UNION ALL
SELECT 'A' AS call_id, 'success' AS outcome
)
SELECT *
FROM (
SELECT call_id, ARRAY_AGG(outcome) AS outcome
FROM test
GROUP BY call_id
) AS sub
WHERE outcome && ARRAY[NULL]
但是這個查詢的結果是沒有行被返回。 ARRAY_AGG
將創建一行,其中call_id
='A'和outcome
數組等於{,'success'}。我如何檢查這個數組的NULL值?
也許這將幫助:http://stackoverflow.com/questions/34848009/check-if-null-exists-in-postgres-array/34848472#34848472 – verhie
這是有趣的,但' ...其中array_position(結果,null)不爲空應該工作。 – Abelisto