From ff3f5a1f4c2d09cf1770e6f727965c4aa7a4da20 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 12 Nov 2015 12:07:15 +0100 Subject: [PATCH] Removes unnecessary arrays --- server/extension/sql/0.0.1/70_ips.sql | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/server/extension/sql/0.0.1/70_ips.sql b/server/extension/sql/0.0.1/70_ips.sql index 65630aa..b40a9aa 100644 --- a/server/extension/sql/0.0.1/70_ips.sql +++ b/server/extension/sql/0.0.1/70_ips.sql @@ -31,16 +31,13 @@ RETURNS Geometry AS $$ DECLARE ret Geometry; - new_ips INET[]; - old_ips TEXT[]; + new_ip INET; BEGIN BEGIN IF family(ip::inet) = 6 THEN - new_ips := array_append(new_ips, ip::inet); - old_ips := array_append(old_ips, ip); + new_ip := ip::inet; ELSE - new_ips := array_append(new_ips, ('::ffff:' || ip)::inet); - old_ips := array_append(old_ips, ip); + new_ip := ('::ffff:' || ip)::inet; END IF; EXCEPTION WHEN OTHERS THEN SELECT ip AS q, NULL as geom, FALSE as success INTO ret; @@ -48,7 +45,7 @@ RETURNS Geometry AS $$ END; WITH - ips AS (SELECT unnest(old_ips) s, unnest(new_ips) net), + ips AS (SELECT ip s, new_ip 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 geom INTO ret FROM matches;