question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add lateral join methods

See original GitHub issue

I’ve been monkey-patching knex to include some lateral join methods but it’d be nice if the library actually supported them. Adding some kind of extra parameter to the existing join methods would be a potentially breaking change, not to mention the existing method signatures aren’t all compatible (lateral joins have to use a subquery). So I propose adding 8 additional methods:

  • innerJoinLateral
  • leftJoinLateral
  • leftOuterJoinLateral
  • rightJoinLateral
  • rightOuterJoinLateral
  • outerJoinLateral
  • fullOuterJoinLateral
  • crossJoinLateral

Signatures would look something like:

(raw: Raw): QueryBuilder;
(subquery: QueryCallback, on: JoinCallback): QueryBuilder;
(subquery: QueryCallback, on: Raw): QueryBuilder;
(subquery: QueryCallback, columns: { [key: string]: string | number | boolean | Raw }): QueryBuilder;
(subquery: QueryCallback, column1: string, column2: string): QueryBuilder;
(subquery: QueryCallback, column1: string, column2: Raw): QueryBuilder;
(subquery: QueryCallback, column1: string, operator: string, column2: string): QueryBuilder;

I can try to put together a PR, but I wanted to confirm this sort of change would be acceptable first.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
ghostcommented, Apr 8, 2020

And MySQL 8 seems support it too, at least I am using this query without troubles:

SELECT e0.id, e1.* FROM gallery AS e0 LEFT JOIN LATERAL (
    SELECT e2.* FROM photo AS e2 WHERE e2.gallery_id = e0.id LIMIT ?
) AS e1 ON e0.id = e1.gallery_id WHERE gallery_id IN (?)
2reactions
elhigucommented, Mar 18, 2020

Yep it would. If we can come up with some abstraction, which works in multiple databases more work is needed to investigate how exactly each DB supports it and design some API for it which can be supported by most of the drivers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use Lateral Joins in PostgreSQL - PopSQL
The lateral keyword allows us to access columns after the FROM statement, and reference these columns "earlier" in the query ("earlier" meaning "written...
Read more >
LATERAL Join - Apache Drill
A lateral join is essentially a foreach loop in SQL. A lateral join is represented by the keyword LATERAL with an inner subquery...
Read more >
Understanding LATERAL joins in PostgreSQL - CYBERTEC
LATERAL joins are one of the lesser-known features of PostgreSQL and other relational databases such as Oracle, DB2 and MS SQL.
Read more >
Lateral Joins - YouTube
How to use Lateral Joins to more efficiently aggregate columns. This episode is brought to you by Hashrocket, a consultancy with expertise ...
Read more >
How to Use Lateral Joins | Analysis | Postgre SQL
This section is all about Lateral Joins, import csv, query json column, etc in PosgreSQl.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found