Answer the question
In order to leave comments, you need to log in
How to escape table name?
Hello! How to properly escape the table name?
Now when asked:
CREATE OR REPLACE FUNCTION foo(_path VARCHAR)
RETURNS FLOAT AS $$
DECLARE
_Table TEXT;
_Value FLOAT;
BEGIN
IF (SELECT EXISTS(SELECT 1 from _glossary WHERE configuration = _path)) THEN
_Table := (SELECT tablename FROM _glossary WHERE configuration = _path);
ELSE
_Table := NULL;
END IF;
EXECUTE FORMAT('SELECT val FROM %I ORDER BY key DESC LIMIT 1', _Table) INTO _Value;
RETURN _Value;
END;
$$ LANGUAGE plpgsql;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question