Fixes cdb_geocoder_server.geocode_ip_point
This commit is contained in:
parent
b54c417754
commit
50abb76b6b
@ -7,7 +7,7 @@ SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0
|
||||
(1 row)
|
||||
|
||||
-- Insert dummy data into ip_address_locations
|
||||
INSERT INTO ip_address_locations VALUES ('0.0.0.0'::inet, (ST_SetSRID(ST_MakePoint('40.40', '3.71'), 4326)));
|
||||
INSERT INTO ip_address_locations VALUES ('::ffff:0.0.0.0'::inet, (ST_SetSRID(ST_MakePoint('40.40', '3.71'), 4326)));
|
||||
-- This should return the polygon inserted above
|
||||
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
||||
geocode_ip_point
|
||||
|
@ -29,15 +29,28 @@ $$ LANGUAGE plpythonu;
|
||||
CREATE OR REPLACE FUNCTION _geocode_ip_point(ip TEXT)
|
||||
RETURNS Geometry AS $$
|
||||
DECLARE
|
||||
ret Geometry;
|
||||
ret geocode_ip_v1%rowtype;
|
||||
|
||||
LIM INTEGER := 1;
|
||||
new_ips INET[];
|
||||
old_ips TEXT[];
|
||||
BEGIN
|
||||
SELECT ips.the_geom as geom INTO ret
|
||||
FROM public.ip_address_locations ips
|
||||
WHERE ips.network_start_ip = ip::inet
|
||||
LIMIT LIM;
|
||||
|
||||
BEGIN
|
||||
IF family(ip::inet) = 6 THEN
|
||||
new_ips := array_append(new_ips, ip::inet);
|
||||
old_ips := array_append(old_ips, ip);
|
||||
ELSE
|
||||
new_ips := array_append(new_ips, ('::ffff:' || ip)::inet);
|
||||
old_ips := array_append(old_ips, ip);
|
||||
END IF;
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
SELECT ip AS q, NULL as geom, FALSE as success INTO ret;
|
||||
RETURN ret;
|
||||
END
|
||||
END;
|
||||
FOR ret IN WITH ips AS (SELECT unnest(old_ips) s, unnest(new_ips) net),
|
||||
matches AS (SELECT s, (SELECT the_geom FROM ip_address_locations WHERE network_start_ip <= ips.net ORDER BY network_start_ip DESC LIMIT 1) geom FROM ips)
|
||||
SELECT s, geom, CASE WHEN geom IS NULL THEN FALSE ELSE TRUE END AS success FROM matches
|
||||
LOOP
|
||||
RETURN ret.geom;
|
||||
END LOOP;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
@ -3,7 +3,7 @@
|
||||
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
||||
|
||||
-- Insert dummy data into ip_address_locations
|
||||
INSERT INTO ip_address_locations VALUES ('0.0.0.0'::inet, (ST_SetSRID(ST_MakePoint('40.40', '3.71'), 4326)));
|
||||
INSERT INTO ip_address_locations VALUES ('::ffff:0.0.0.0'::inet, (ST_SetSRID(ST_MakePoint('40.40', '3.71'), 4326)));
|
||||
|
||||
-- This should return the polygon inserted above
|
||||
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
||||
|
Loading…
Reference in New Issue
Block a user