-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LATERAL constant string doesn't have JOIN inside #2205
Comments
I'm following the examples provided here in pg's doc: https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-LATERAL I suppose we probably also need to support an inner lateral join, too, though I'm not sure how that would be used. |
The way I'm currently going to address this is to add the This gives you the opportunity to use joins more naturally, and signifies only that the subquery being joined should be interpreted as a lateral join, which I think is more "correct" anyways. Example: # Here we use a subquery to get the most-recent two tweets by each user.
subq = (Tweet
.select(Tweet.content, Tweet.timestamp)
.where(Tweet.user == User.id)
.order_by(Tweet.timestamp.desc())
.limit(2)
.lateral())
# Here we do an inner join on the (lateral) subquery of tweets.
query = (User
.select(User, subq.c.content)
.join(subq, on=True)
.order_by(subq.c.timestamp)) |
The example that you referred to with only Above clause is equivalent to I do like the current API of |
JOIN.LATERAL
constant string currently only contains'LATERAL'
, which causes syntax error with Postgresql. It should be either'INNER JOIN LATERAL'
or simply'JOIN LATERAL'
JOIN.LEFT_LATERAL
is correct though ('LEFT JOIN LATERAL'
).The text was updated successfully, but these errors were encountered: