I need to return "select * from table1 t1 join table2 t2 on t1.id = t2.t2id where t1.id = _id" using function get_data(_id).
I fount solution: https://stackoverflow.com/a/11751557 But there is result from one table, and I can't understand is this possible to add join to this query to get result from multiple table?
I tried:
CREATE OR REPLACE FUNCTION get_data_test_2(_tbl_type anyelement,_tbl_type_2 anyelement, _id int)
  RETURNS SETOF anyelement
  LANGUAGE plpgsql AS
$func$
BEGIN
   RETURN QUERY EXECUTE format('
      SELECT *
      FROM  %s as s1  -- pg_typeof returns regtype, quoted automatically
      left join %s as s2 on s1.id = s2.t1id
      WHERE  id = s1.'||_id||''
    , pg_typeof(_tbl_type))
   USING  _id;
END
$func$;
But obviously it's not working UPD Main problem that I need to get all columns from joined tables dynamically without setting explicit columns names.
 
    