Hello
I can not reproduce
psql (10.4 (Debian 10.4-1.pgdg80+1))
Type "help" for help.
postgres=# WITH test_cte AS (SELECT 1 AS id, 2 AS qty)
SELECT COALESCE(SUM(qty), 0) FROM test_cte WHERE id=2;
coalesce
----------
0
(1 row)
postgres=# WITH test_cte AS (SELECT 1 AS id, 2 AS qty)
SELECT COALESCE((SELECT SUM(qty) FROM test_cte WHERE id=2), 0);
coalesce
----------
0
(1 row)
Can you give more complete example?
regards, Sergei