How are you executing that function? It works as a select statement.
Create a table: public.users
create table public.users (id int, firstname varchar, lastname varchar);
Insert some records:
insert into public.users values (1, 'aaa','bbb'),(2,'ccc','ddd');
function: my_function
CREATE OR REPLACE FUNCTION my_function(user_id integer) RETURNS TABLE(id integer, firstname character varying, lastname character varying) AS $$
DECLARE
ids INTEGER[];
BEGIN
ids := ARRAY[1,2];
RETURN QUERY
SELECT users.id, users.firstname, users.lastname
FROM public.users
WHERE users.id = ANY(ids);
END;
$$ LANGUAGE plpgsql;
Now you can use with *
select * from my_function(1);
Result of query
id | firstname | lastname
----+-----------+----------
1 | aaa | bbb
2 | ccc | ddd
Or with column names as well
select id,firstname,lastname from my_function(1);
Result
id | firstname | lastname
----+-----------+----------
1 | aaa | bbb
2 | ccc | ddd
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…