Reputation: 10035
Given some very complex and expensive SQL query result with two columns - some complex data
and a boolean flag
, is there a way in PostgreSQL to:
flag
column is true
, the result should be empty.flag
value.-- This needs filtering:
SELECT data, flag FROM (...) src;
Upvotes: 0
Views: 51
Reputation: 248030
A strange requirement, but window functions can do it:
SELECT data, flag
FROM (SELECT data, flag,
count(*) OVER () AS c
FROM (SELECT ...) AS src
) AS q
WHERE NOT flag OR c <> 1;
Upvotes: 1