So, I'm trying to get the postal codes of a city (polygon). Unfortunately, I never get consistent results with my code:
SELECT
a.name,
b.tags->'postal_code'
FROM planet_osm_polygon a
JOIN planet_osm_polygon b ON ST_Intersects(a.way, b.way)
WHERE a.name = 'cityname'
AND b.boundary = 'postal_code';
With ST_Intersects
I get all valid postal codes plus a few non-valid surrounding ones.
I also tried a few other functions, like ST_Crosses
, ST_Contains
, ST_Within
, but never got a set of valid postal codes. Is there a best practice out there to solve this?