I want to do something like LINQ SelectMany in Postgres SQL. I have a function with a signature like this:
CREATE or REPLACE FUNCTION get_objects(id_in int) RETURNS TABLE (name varchar, id_out int)
Each call on it returns 200 rows.
I have a select that returns a table of in_IDs. I want to call my function on each row of such a table and merge them into a single one. In other words, join many lists of rows into a single big table. How to do such a thing in Postgres SQL (not inside function loop)?
CodePudding user response:
Use lateral join.
select l.*
from the_table_of_in_ids as t -- or put the query in brackets here
cross join lateral get_objects(t.id) as l;