back

by MrBuddyCasino·11y ago·view on hn ↗
As someone who only works now and then with Postgres, this is what made it click for me:

"Loosely, it means that a LATERAL join is like a SQL foreach loop, in which PostgreSQL will iterate over each row in a result set and evaluate a subquery using that row as a parameter."

1 comments
Sounds like what Oracle calls a "correlated subquery" is it the same thing?
No, Postgres has supported those for a long time. For example:

    SELECT *
    FROM   employees e
    WHERE  EXISTS (SELECT 1
                   FROM   employee_projects ep
                   WHERE  ep.employee_id = e.id
                   AND    ep.project_id = 5)
    ;
This new feature is a lot like correlated subqueries except you can put that nested SELECT into the FROM clause and still access the employees table.