Skip to content

Commit 8c7cc60

Browse files
committed
Use place_addressline for building hierarchy on import
1 parent c1f1a1d commit 8c7cc60

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

importer/src/main.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,22 @@ int main(int argc, char *argv[])
153153
pqxx::work txn{ pgc };
154154

155155
const std::string base_query
156-
= "select place_id, linked_place_id, parent_place_resolved as parent_place_id, country_code, "
157-
"class, type, "
158-
"hstore_to_json(name) as name, hstore_to_json(extratags) as extra, "
159-
"COALESCE(address->'housenumber',housenumber) AS housenumber, postcode, ST_X(centroid) as "
160-
"longitude, ST_Y(centroid) as latitude, osm_id "
161-
"from placex pl left join lateral "
162-
"(with recursive prec as (select place_id, linked_place_id "
163-
"from placex where pl.parent_place_id=placex.place_id union select p.place_id, "
164-
"p.linked_place_id from placex p join prec on p.place_id=prec.linked_place_id) select "
165-
"place_id as parent_place_resolved from prec where linked_place_id is null limit 1) as "
166-
"pres on true ";
156+
= R"SQL(
157+
select place_id, linked_place_id, parent_place_resolved as parent_place_id, country_code, class, type,
158+
hstore_to_json(name) as name, hstore_to_json(extratags) as extra,
159+
COALESCE(address->'housenumber',housenumber) AS housenumber,
160+
postcode, ST_X(centroid) as longitude, ST_Y(centroid) as latitude,
161+
osm_type, osm_id
162+
from placex pl
163+
left join lateral
164+
(select address_place_id from place_addressline a where a.place_id=pl.place_id
165+
order by cached_rank_address desc limit 1) as a on true
166+
left join lateral
167+
(with recursive prec as
168+
(select place_id, linked_place_id from placex where COALESCE(a.address_place_id,pl.parent_place_id)=placex.place_id
169+
union select p.place_id, p.linked_place_id from placex p join prec on p.place_id=prec.linked_place_id)
170+
select place_id as parent_place_resolved from prec where linked_place_id is null limit 1) as pres on true
171+
)SQL";
167172

168173
// load primary hierarchy
169174
{

0 commit comments

Comments
 (0)