I have this function:
CREATE OR REPLACE FUNCTION remote (_table_name text)
RETURNS SETOF my_table AS
$func$
DECLARE
sql text := format('SELECT * FROM %s WHERE id = 1', _table_name);
BEGIN
RETURN QUERY EXECUTE sql
USING _table_name;
END
$func$ LANGUAGE plpgsql;
select * from remote('my_table')
But I would like to have a dynamic RETURNS SETOF _table_name
.
I get this error if I do so:
ERROR: type "_table_name" does not exist
How can I achieve that?
Many thanks