CREATE OR REPLACE FUNCTION getParentLtree(parent_id bigint, tbl_name varchar)
RETURNS ltree AS
$BODY$
DECLARE
parent_ltree ltree;
BEGIN
EXECUTE format('select into parent_ltree l_tree from %I
where id = %I', tbl_name,parent_id);
RETURN parent_ltree;
END;
$BODY$ LANGUAGE plpgsql;
There are 2 problems in the function above:
parent_idis there integer, but is replaced by quotation marks? What is the correct format specifier for variables int?select intonot working with EXECUTE? How can I make the above commented request to use the passed table name?
source
share