![]() ![]() A correlated subquery can only return a single value, not multiple columns and not multiple rows - with the exception of bare function calls (which multiply result rows if they return multiple rows). There are things that a LATERAL join can do, but a (correlated) subquery cannot (easily). Call a set-returning function with an array argument multiple times. ![]() Optimize GROUP BY query to retrieve latest row per userįor returning more than one column, a LATERAL join is typically simpler, cleaner and faster.Īlso, remember that the equivalent of a correlated subquery is LEFT JOIN LATERAL.Related answer with code examples for both side by side, solving the same problem: (The query planner has ways to optimize performance for either, though.) More like a correlated subqueryĪ LATERAL join is more like a correlated subquery, not a plain subquery, in that expressions to the right of a LATERAL join are evaluated once for each row left of it - just like a correlated subquery - while a plain subquery (table expression) is evaluated once only. Word LATERAL, but for functions the key word is optional theįunction's arguments can contain references to columns provided byīasic code examples are given there. Table functions appearing in FROM can also be preceded by the key Independently and so cannot cross-reference any other FROM item.) (Without LATERAL, each subquery is evaluated This allows them to reference columns provided by precedingįROM items. Subqueries appearing in FROM can be preceded by the key word The feature was introduced with PostgreSQL 9.3.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |