I have a Postgres function that RETURNS TABLE. I want to return an empty table in the event that a CTE has zero rows. Something like
SELECT (CASE WHEN (SELECT count(1) FROM mycte = 0)
THEN (SELECT ... ??) -- not sure what to put here to return zero rows
ELSE (SELECT ...) -- A normal database query
END)
How can I accomplish this? Just writing SELECT
with nothing else returns a single column. SELECT x, y FROM ()
doesn't work. SELECT (SELECT , SELECT)
doesn't work.