How to return two columns with function
Table functions (functions defined as returns table or returns setof) need to be used in the from clause like a table. So you need to use: select * from get_avg_prices(…); Only scalar functions (functions which return only a single value, e.g. a number) should be put into the select list.