COALESCE with CTEs displays NULL
klaxian opened this issue · 1 comments
When issuing certain SELECT
queries through phpPgAdmin that contain COALESCE
, NULL
results are displayed instead of the value(s) that COALESCE
actually returned. I suspect that phpPgAdmin is wrapping client queries in some way behind the scenes even though "Paginate results" is not checked. Proof-of-concept examples are below. Both of these return 0 when using the psql client, but NULL is displayed in phpPgAdmin. The PostgreSQL developers confirmed this is not a problem with the database server nor client.
WITH test_cte AS (SELECT 1 AS id, 2 AS qty)
SELECT COALESCE(SUM(qty), 0) FROM test_cte WHERE id=2;
WITH test_cte AS (SELECT 1 AS id, 2 AS qty)
SELECT COALESCE((SELECT SUM(qty) FROM test_cte WHERE id=2), 0);
You are right. The printval method of Misc class is shortcutting falsy values to null, which is a bug. I have already fixed this behavior in the develop branch, and I'm releasing a new tag tomorrow patching the bug.