I am attempting to retrieve either a null or boolean value from a query. Here is my query:
SELECT EXISTS (SELECT 1 FROM employee
where add_uuid = '7e53fa47-ade3-4e94-8efd-b25f998b09c6') AS a,
CASE WHEN a = false then null
ELSE (SELECT exists (SELECT 1 FROM employee
where add_uuid = '7e53fa47-ade3-4e94-8efd-b25f998b09c6'
and is_active = true
)
)
END
Results in:
SQL Error [42703]: ERROR: column "a" does not exist
Despite experimenting with multiple options, I am still unable to achieve the desired outcome.
WITH foo AS (SELECT a, b, a+b AS c FROM tbl), bar AS (SELECT a, b, c, c::BIGINT AS d, c - c::BIGINT AS e) SELECT d, e FROM bar;