By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
with my_table as
(
select 'url1' url, 'desc1' description, 'All' for_country
union all
select 'url2' url, 'desc2' description, 'All' for_country
union all
select 'url2' url, 'desc3' description, 'h' for_country
)
select my_table.*
from my_table
cross join (
select EXISTS (select 1 from my_table where for_country='Germany') exst
) t
where (t.exst and for_country='Germany') OR
(not t.exst and for_country='All')
url | description | for_country |
---|---|---|
url1 | desc1 | All |
url2 | desc2 | All |