create table t1
as select n as id, md5(n::text) as txt
from generate_series(1, 10) s(n);
create table t2
as select n as id, md5((n + 100)::text) as txt
from generate_series(1, 10) s(n);
create function func_test()
returns table (id int, txt text, txt2 text)
language plpgsql
as $$
declare qry text;
begin
qry := $q$select t1.*, t2.txt as txt2 from t1 join t2 using(id)$q$;
return query execute qry;
end;
$$;
select *
from func_test();