2015-11-10 22:28:12 +08:00
|
|
|
--
|
|
|
|
-- This extension has its own table for configurations.
|
|
|
|
--
|
|
|
|
-- The table and the function are considered to be private and therefore
|
|
|
|
-- no permissions are granted for any other user but the creator.
|
|
|
|
|
2015-11-11 23:52:45 +08:00
|
|
|
CREATE TABLE IF NOT EXISTS cdb_geocoder_client._config ( KEY TEXT PRIMARY KEY, VALUE JSON NOT NULL );
|
2015-11-10 22:28:12 +08:00
|
|
|
|
|
|
|
-- Needed to dump config in backups
|
|
|
|
-- This can only be called from an SQL script executed by CREATE EXTENSION
|
2015-11-11 23:52:45 +08:00
|
|
|
SELECT pg_catalog.pg_extension_config_dump('cdb_geocoder_client._config', '');
|
2015-11-10 22:28:12 +08:00
|
|
|
|
|
|
|
|
2015-11-11 23:52:45 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._config_set(key text, value JSON)
|
2015-11-10 22:28:12 +08:00
|
|
|
RETURNS VOID AS $$
|
|
|
|
BEGIN
|
2015-11-11 23:52:45 +08:00
|
|
|
PERFORM cdb_geocoder_client._config_remove(key);
|
|
|
|
EXECUTE 'INSERT INTO cdb_geocoder_client._config (KEY, VALUE) VALUES ($1, $2);' USING key, value;
|
2015-11-10 22:28:12 +08:00
|
|
|
END
|
|
|
|
$$ LANGUAGE PLPGSQL VOLATILE;
|
|
|
|
|
|
|
|
|
2015-11-11 23:52:45 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._config_remove(key text)
|
2015-11-10 22:28:12 +08:00
|
|
|
RETURNS VOID AS $$
|
|
|
|
BEGIN
|
2015-11-11 23:52:45 +08:00
|
|
|
EXECUTE 'DELETE FROM cdb_geocoder_client._config WHERE KEY = $1;' USING key;
|
2015-11-10 22:28:12 +08:00
|
|
|
END
|
|
|
|
$$ LANGUAGE PLPGSQL VOLATILE;
|
|
|
|
|
2015-11-11 23:52:45 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_geocoder_client._config_get(key text)
|
2015-11-10 22:28:12 +08:00
|
|
|
RETURNS JSON AS $$
|
|
|
|
DECLARE
|
|
|
|
value JSON;
|
|
|
|
BEGIN
|
2015-11-11 23:52:45 +08:00
|
|
|
EXECUTE 'SELECT VALUE FROM cdb_geocoder_client._config WHERE KEY = $1;' INTO value USING key;
|
2015-11-10 22:28:12 +08:00
|
|
|
RETURN value;
|
|
|
|
END
|
2015-11-11 23:52:45 +08:00
|
|
|
$$ LANGUAGE PLPGSQL STABLE;
|