Configuration table and functions

This commit is contained in:
Juan Ignacio Sánchez Lara 2015-08-13 20:43:17 +02:00
parent 7262d34b06
commit 725453ce2b

View File

@ -0,0 +1,33 @@
DO LANGUAGE 'plpgsql' $$
BEGIN
CREATE TABLE IF NOT EXISTS CDB_CONF ( PARAM TEXT PRIMARY KEY, VALUE TEXT NOT NULL );
END
$$;
CREATE OR REPLACE
FUNCTION cartodb.CDB_Conf_SetParam(param text, value text)
RETURNS void AS $$
BEGIN
PERFORM cartodb.CDB_Conf_RemoveParam(param);
EXECUTE 'INSERT INTO CDB_CONF (PARAM, VALUE) VALUES ($1, $2);' USING param, value;
END
$$ LANGUAGE PLPGSQL VOLATILE;
CREATE OR REPLACE
FUNCTION cartodb.CDB_Conf_RemoveParam(param text)
RETURNS void AS $$
BEGIN
EXECUTE 'DELETE FROM CDB_CONF WHERE PARAM = $1;' USING param;
END
$$ LANGUAGE PLPGSQL VOLATILE;
CREATE OR REPLACE
FUNCTION cartodb.CDB_Conf_GetParam(param text)
RETURNS TEXT AS $$
DECLARE
value TEXT;
BEGIN
EXECUTE 'SELECT VALUE FROM CDB_CONF WHERE PARAM = $1;' INTO value USING param;
RETURN value;
END
$$ LANGUAGE PLPGSQL STABLE;