1 create type nearplace as (
5 create type nearfeature as (
14 CREATE TABLE location_area_large_-partition- () INHERITS (location_area_large);
15 CREATE INDEX idx_location_area_large_-partition-_geometry ON location_area_large_-partition- USING GIST (geometry);
17 CREATE TABLE location_area_roadnear_-partition- () INHERITS (location_area_roadnear);
18 CREATE INDEX idx_location_area_roadnear_-partition-_geometry ON location_area_roadnear_-partition- USING GIST (geometry);
20 CREATE TABLE location_area_roadfar_-partition- () INHERITS (location_area_roadfar);
21 CREATE INDEX idx_location_area_roadfar_-partition-_geometry ON location_area_roadfar_-partition- USING GIST (geometry);
24 create or replace function getNearRoads(in_partition TEXT, point GEOMETRY) RETURNS setof nearplace AS $$
30 IF in_partition = '-partition-' THEN
31 FOR r IN SELECT place_id FROM location_area_large WHERE partition = '-partition-' and ST_Contains(geometry, point) LOOP
38 RAISE EXCEPTION 'Unknown partition %', in_partition;
43 create or replace function getNearFeatures(in_partition TEXT, point GEOMETRY, maxrank INTEGER) RETURNS setof nearfeature AS $$
45 r nearfeature%rowtype;
49 IF in_partition = '-partition-' THEN
55 ST_Distance(place_centroid, centroid) as distance
56 FROM location_area_large
57 WHERE ST_Contains(area, point) and location_area_large.rank_search < maxrank
58 ORDER BY ST_Distance(place_centroid, centroid) ASC
66 RAISE EXCEPTION 'Unknown partition %', in_partition;
71 create or replace function deleteLocationArea(in_partition TEXT, in_place_id bigint) RETURNS BOOLEAN AS $$
76 IF in_partition = '-partition-' THEN
77 DELETE from location_area_large_-partition- WHERE place_id = in_place_id;
78 DELETE from location_area_roadnear_-partition- WHERE place_id = in_place_id;
79 DELETE from location_area_roadfar_-partition- WHERE place_id = in_place_id;
84 RAISE EXCEPTION 'Unknown partition %', in_partition;
91 create or replace function insertLocationAreaLarge(
92 in_partition TEXT, in_place_id bigint, in_keywords INTEGER[],
93 in_rank_search INTEGER, in_rank_address INTEGER, in_estimate BOOLEAN,
94 in_centroid GEOMETRY, in_geometry GEOMETRY) RETURNS BOOLEAN AS $$
99 IF in_partition = '-partition-' THEN
100 INSERT INTO location_area_large_-partition- values (in_partition, in_place_id, in_keywords, in_rank_search, in_rank_address, in_estimate, in_centroid, in_geometry);
105 RAISE EXCEPTION 'Unknown partition %', in_partition;
111 create or replace function insertLocationAreaRoadNear(
112 in_partition TEXT, in_place_id bigint, in_keywords INTEGER[],
113 in_rank_search INTEGER, in_rank_address INTEGER, in_estimate BOOLEAN,
114 in_centroid GEOMETRY, in_geometry GEOMETRY) RETURNS BOOLEAN AS $$
119 IF in_partition = '-partition-' THEN
120 INSERT INTO location_area_roadnear_-partition- values (in_partition, in_place_id, in_keywords, in_rank_search, in_rank_address, in_estimate, in_centroid, in_geometry);
125 RAISE EXCEPTION 'Unknown partition %', in_partition;
131 create or replace function insertLocationAreaRoadFar(
132 in_partition TEXT, in_place_id bigint, in_keywords INTEGER[],
133 in_rank_search INTEGER, in_rank_address INTEGER, in_estimate BOOLEAN,
134 in_centroid GEOMETRY, in_geometry GEOMETRY) RETURNS BOOLEAN AS $$
139 IF in_partition = '-partition-' THEN
140 INSERT INTO location_area_roadfar_-partition- values (in_partition, in_place_id, in_keywords, in_rank_search, in_rank_address, in_estimate, in_centroid, in_geometry);
145 RAISE EXCEPTION 'Unknown partition %', in_partition;