+ RETURN;
+ END IF;
+-- end
+
+ RAISE EXCEPTION 'Unknown partition %', in_partition;
+END
+$$
+LANGUAGE plpgsql;
+
+create or replace function deleteLocationArea(in_partition INTEGER, in_place_id BIGINT) RETURNS BOOLEAN AS $$
+DECLARE
+BEGIN
+
+-- start
+ IF in_partition = -partition- THEN
+ DELETE from location_area_large_-partition- WHERE place_id = in_place_id;
+ RETURN TRUE;
+ END IF;
+-- end
+
+ RAISE EXCEPTION 'Unknown partition %', in_partition;
+
+ RETURN FALSE;
+END
+$$
+LANGUAGE plpgsql;
+
+create or replace function insertLocationAreaLarge(
+ in_partition INTEGER, in_place_id BIGINT, in_country_code VARCHAR(2), in_keywords INTEGER[],
+ in_rank_search INTEGER, in_rank_address INTEGER, in_estimate BOOLEAN,
+ in_centroid GEOMETRY, in_geometry GEOMETRY) RETURNS BOOLEAN AS $$
+DECLARE
+BEGIN
+
+ IF in_rank_search <= 4 THEN
+ INSERT INTO location_area_country values (in_partition, in_place_id, in_country_code, in_keywords, in_rank_search, in_rank_address, in_estimate, in_centroid, in_geometry);
+ RETURN TRUE;
+ END IF;
+
+-- start
+ IF in_partition = -partition- THEN
+ INSERT INTO location_area_large_-partition- values (in_partition, in_place_id, in_country_code, in_keywords, in_rank_search, in_rank_address, in_estimate, in_centroid, in_geometry);
+ RETURN TRUE;
+ END IF;
+-- end
+
+ RAISE EXCEPTION 'Unknown partition %', in_partition;
+ RETURN FALSE;
+END
+$$
+LANGUAGE plpgsql;
+
+create or replace function getNearestNamedFeature(in_partition INTEGER, point GEOMETRY, maxrank INTEGER, isin_token INTEGER) RETURNS setof nearfeature AS $$
+DECLARE
+ r nearfeature%rowtype;
+BEGIN
+
+-- start
+ IF in_partition = -partition- THEN
+ FOR r IN
+ SELECT place_id, name_vector, address_rank, search_rank,
+ ST_Distance(centroid, point) as distance, null as isguess
+ FROM search_name_-partition-
+ WHERE name_vector @> ARRAY[isin_token]
+ AND search_rank < maxrank
+ UNION ALL
+ SELECT place_id, name_vector, address_rank, search_rank,
+ ST_Distance(centroid, point) as distance, null as isguess
+ FROM search_name_country
+ WHERE name_vector @> ARRAY[isin_token]
+ AND search_rank < maxrank
+ ORDER BY distance ASC limit 1
+ LOOP