diff --git a/client/sql/0.0.1/06_geocoder_server_conn.sql b/client/sql/0.0.1/06_geocoder_server_conn.sql new file mode 100644 index 0000000..dd53dc3 --- /dev/null +++ b/client/sql/0.0.1/06_geocoder_server_conn.sql @@ -0,0 +1,16 @@ +-- +-- Geocoder server connection config +-- +-- The purpose of this function is provide to the PL/Proxy functions +-- the connection string needed to connect with the server + +CREATE OR REPLACE FUNCTION cdb_geocoder_client._server_conn_str() +RETURNS text AS $$ +DECLARE + db_connection_str text; +BEGIN + SELECT cdb_geocoder_client._config_get('db_server_config')->'connection_str' INTO db_connection_str; + SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str; + RETURN db_connection_str; +END; +$$ LANGUAGE 'plpgsql'; \ No newline at end of file diff --git a/client/sql/0.0.1/10_admin0.sql b/client/sql/0.0.1/10_admin0.sql index c652462..a548627 100644 --- a/client/sql/0.0.1/10_admin0.sql +++ b/client/sql/0.0.1/10_admin0.sql @@ -7,12 +7,9 @@ CREATE OR REPLACE FUNCTION cdb_geocoder_client.geocode_admin0_polygons(country_name text) RETURNS Geometry AS $$ DECLARE - db_connection_str text; ret Geometry; BEGIN - SELECT cdb_geocoder_client._config_get('db_server_config')->'connection_str' INTO db_connection_str; - SELECT trim(both '"' FROM db_connection_str) INTO db_connection_str; - SELECT cdb_geocoder_client._geocode_admin0_polygons(session_user, txid_current(), db_connection_str, country_name) INTO ret; + SELECT cdb_geocoder_client._geocode_admin0_polygons(session_user, txid_current(), country_name) INTO ret; RETURN ret; END; $$ LANGUAGE 'plpgsql' SECURITY DEFINER; @@ -22,9 +19,9 @@ $$ LANGUAGE 'plpgsql' SECURITY DEFINER; -------------------------------------------------------------------------------- -CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin0_polygons(user_id name, tx_id bigint, db_connection_str text, country_name text) +CREATE OR REPLACE FUNCTION cdb_geocoder_client._geocode_admin0_polygons(user_id name, tx_id bigint, country_name text) RETURNS Geometry AS $$ -- TODO check if we can move the config to its own function - CONNECT db_connection_str; + CONNECT cdb_geocoder_client._server_conn_str(); SELECT cdb_geocoder_server.geocode_admin0_polygons(user_id, tx_id, country_name); $$ LANGUAGE plproxy;