X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/a437f5d18a48d3f982e965ef81c93f71a73e53e0..e1b096cf8cf1ac6904c9adf0963f0e1756ca65ea:/sql/functions/postcode_triggers.sql?ds=inline

diff --git a/sql/functions/postcode_triggers.sql b/sql/functions/postcode_triggers.sql
index 96788d65..515b7666 100644
--- a/sql/functions/postcode_triggers.sql
+++ b/sql/functions/postcode_triggers.sql
@@ -27,8 +27,8 @@ BEGIN
     NEW.parent_place_id = 0;
     FOR location IN
       SELECT place_id
-        FROM getNearFeatures(partition, NEW.geometry, NEW.rank_search, '{}'::int[])
-        WHERE NOT isguess ORDER BY rank_address DESC LIMIT 1
+        FROM getNearFeatures(partition, NEW.geometry, NEW.rank_search)
+        WHERE NOT isguess ORDER BY rank_address DESC, distance asc LIMIT 1
     LOOP
         NEW.parent_place_id = location.place_id;
     END LOOP;
