I have the following function that takes a table name as parameter and returns the table:
CREATE FUNCTION func(tab_name varchar) RETURNS TABLE (
col text,
col2 text
) AS $$
BEGIN
RETURN QUERY
EXECUTE format('SELECT * FROM %I', tab_name);
END;
$$
LANGUAGE plpgsql;
Suppose instead, I wanted to do return the table 100 times:
CREATE FUNCTION func(tab_name varchar) RETURNS TABLE (
col text,
col2 text
) AS $$
BEGIN
RETURN QUERY
EXECUTE format('
SELECT * FROM %I
UNION ALL
SELECT * FROM %I,
UNION ALL
SELECT * FROM %I
......
', tab_name, tab_name, tab_name,.....);
END;
$$
LANGUAGE plpgsql;
Instead of putting tab_name 100 times is there some way to use named parameters?