select * from
(
select ways.id as wayid,relations.id as relid,wlanduse.v::text as wlanduse,rlanduse.v::text as rlanduse,count(nodes) as nodes from osm.current_ways ways
left join osm.current_way_nodes nodes on nodes.way_id=ways.id
left join osm.current_way_tags wlanduse on wlanduse.way_id=ways.id and wlanduse.k='landuse'
left join osm.current_relation_members members on members.member_id=ways.id and members.member_role='outer'
left join osm.current_relations relations on relations.id=members.relation_id
left join osm.current_relation_tags rlanduse on rlanduse.relation_id=ways.id and rlanduse.k='landuse'
group by wayid,relid,wlanduse,rlanduse
) foo
where relid is not NULL and (wlanduse = 'forest' or rlanduse = 'forest')
;
