Fixes param type for geocode_ip

This commit is contained in:
Guido Fioravantti 2015-11-11 15:43:11 +01:00
parent 1c44fbbf56
commit 66fd33da37
3 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
-- Check that the public function is callable, even with no data -- Check that the public function is callable, even with no data
-- It should return NULL -- It should return NULL
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0'::inet); SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
geocode_ip_point geocode_ip_point
------------------ ------------------
@ -9,7 +9,7 @@ SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '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 ('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'::inet); SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');
geocode_ip_point geocode_ip_point
---------------------------------------------------- ----------------------------------------------------
0101000020E61000003333333333334440AE47E17A14AE0D40 0101000020E61000003333333333334440AE47E17A14AE0D40

View File

@ -1,6 +1,6 @@
-- Interface of the server extension -- Interface of the server extension
CREATE OR REPLACE FUNCTION geocode_ip_point(user_id NAME, tx_id BIGINT, ip INET) CREATE OR REPLACE FUNCTION geocode_ip_point(user_id NAME, tx_id BIGINT, ip TEXT)
RETURNS Geometry AS $$ RETURNS Geometry AS $$
plpy.debug('Entering _geocode_ip_point') plpy.debug('Entering _geocode_ip_point')
plpy.debug('user_id = %s' % user_id) plpy.debug('user_id = %s' % user_id)
@ -14,7 +14,7 @@ RETURNS Geometry AS $$
#--TODO: quota check #--TODO: quota check
#-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html #-- Copied from the doc, see http://www.postgresql.org/docs/9.4/static/plpython-database.html
plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_ip_point($1) AS point", ["INET"]) plan = plpy.prepare("SELECT cdb_geocoder_server._geocode_ip_point($1) AS point", ["TEXT"])
rv = plpy.execute(plan, [ip], 1) rv = plpy.execute(plan, [ip], 1)
plpy.debug('Returning from _geocode_ip_point') plpy.debug('Returning from _geocode_ip_point')
@ -26,14 +26,14 @@ $$ LANGUAGE plpythonu;
-- Implementation of the server extension -- Implementation of the server extension
-- 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 INET) CREATE OR REPLACE FUNCTION _geocode_ip_point(ip TEXT)
RETURNS Geometry AS $$ RETURNS Geometry AS $$
DECLARE DECLARE
ret Geometry; ret Geometry;
BEGIN BEGIN
SELECT ips.the_geom as geom INTO ret SELECT ips.the_geom as geom INTO ret
FROM public.ip_address_locations ips FROM public.ip_address_locations ips
WHERE ips.network_start_ip = ip; WHERE ips.network_start_ip = ip::inet;
RETURN ret; RETURN ret;
END END

View File

@ -1,9 +1,9 @@
-- Check that the public function is callable, even with no data -- Check that the public function is callable, even with no data
-- It should return NULL -- It should return NULL
SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0'::inet); 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 ('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'::inet); SELECT cdb_geocoder_server.geocode_ip_point(session_user, txid_current(), '0.0.0.0');