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)
|
(1 row)
|
||||||
|
|
||||||
-- Insert dummy data into ip_address_locations
|
-- 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
|
-- This should return the polygon inserted above
|
||||||
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
||||||
geocode_ip_point
|
geocode_ip_point
|
||||||
|
@ -28,16 +28,29 @@ $$ LANGUAGE plpythonu;
|
|||||||
-- Note: these functions depend on the cdb_geocoder extension
|
-- Note: these functions depend on the cdb_geocoder extension
|
||||||
CREATE OR REPLACE FUNCTION _geocode_ip_point(ip TEXT)
|
CREATE OR REPLACE FUNCTION _geocode_ip_point(ip TEXT)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
ret Geometry;
|
ret geocode_ip_v1%rowtype;
|
||||||
|
|
||||||
LIM INTEGER := 1;
|
new_ips INET[];
|
||||||
BEGIN
|
old_ips TEXT[];
|
||||||
SELECT ips.the_geom as geom INTO ret
|
BEGIN
|
||||||
FROM public.ip_address_locations ips
|
BEGIN
|
||||||
WHERE ips.network_start_ip = ip::inet
|
IF family(ip::inet) = 6 THEN
|
||||||
LIMIT LIM;
|
new_ips := array_append(new_ips, ip::inet);
|
||||||
|
old_ips := array_append(old_ips, ip);
|
||||||
RETURN ret;
|
ELSE
|
||||||
END
|
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;
|
||||||
|
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;
|
$$ LANGUAGE plpgsql;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
||||||
|
|
||||||
-- Insert dummy data into ip_address_locations
|
-- 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
|
-- This should return the polygon inserted above
|
||||||
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
|
||||||
|
Loading…
Reference in New Issue
Block a user