workers-sdk: π BUG: when trying to left join 2 tables that have same name columns - second column is not returned
Which Cloudflare product(s) does this pertain to?
D1
What version of Wrangler are you using?
2.19.0
What operating system are you using?
macOS
Describe the Bug
As per issue #555 we can see, that d1 stopped returning duplicate names from different tables. It was working before and itβs how any other driver is doing for raw mode
$ pnpm wrangler d1 execute dzltest --command='select "users"."id", "posts"."id", "posts"."ownerId", "posts"."title", "posts"."content" from "users" left join "posts" on "posts"."ownerId" = "users"."id";'
ββββββ¬ββββββββββ¬ββββββββ¬ββββββββββββ
β id β ownerId β title β content β
ββββββΌββββββββββΌββββββββΌββββββββββββ€
β 2 β 1 β test β 111111111 β
ββββββΌββββββββββΌββββββββΌββββββββββββ€
β 3 β 1 β ueoau β ueueu β
ββββββΌββββββββββΌββββββββΌββββββββββββ€
β 1 β 1 β xxx β yyy β
ββββββ΄ββββββββββ΄ββββββββ΄ββββββββββββ
But should return id for user and id for posts as well
Expected
ββββββ¬βββββ¬ββββββββββ¬ββββββββ¬ββββββββββββ
β id β id β ownerId β title β content β
ββββββΌβββββΌββββββββββΌββββββββΌββββββββββββ€
β 2 β 1 β 1 β test β 111111111 β
ββββββΌβββββΌββββββββββΌββββββββΌββββββββββββ€
β 3 β 2 β 1 β ueoau β ueueu β
ββββββΌβββββΌββββββββββΌββββββββΌββββββββββββ€
β 1 β 3 β 1 β xxx β yyy β
ββββββ΄βββββ΄ββββββββββ΄ββββββββ΄ββββββββββββ
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 15
- Comments: 20 (10 by maintainers)
We are working on this. Current priority is larger databases, which is the biggest ask from most users.
@rozenmd Iβve tested this with latest types version (
4.20240320.1), and the.raw()method still doesnβt return multiple columns with the same name. This change shouldnβt require any actions from our side, since we donβt bundle@cloudflare/workers-typeswith Drizzle, itβs used as a peer dependency, so it should be enough for users to just update their dependency version. However, it doesnβt seem to be the case.Hereβs a reproduction repo: https://github.com/dankochetov/drizzle-d1-bug Iβve added a raw D1 call to make sure it wasnβt Drizzleβs fault, and observed the same behavior. As you could see from the logs, the columns list in the response donβt match the columns list in the query.
Is there any update on resolving this issue? I have tables with the same names for common fields like created_at, updated_at, id etc and joins donβt work because all the response data is shifting columns in the results.
Changelog: https://developers.cloudflare.com/d1/platform/changelog/#2024-02-13
cc @AndriiSherman on the Drizzle team.
@geelen Iβm using the latest wrangler
3.37.0to deploy my app withcompatibility_date = "2024-03-25"and Iβm still facing this issue.Is there anything special I need to do to get the new version?
FYI, this will be fixed D1 once https://github.com/cloudflare/workerd/pull/1586 is merged and rolls out
It will only fix the results of
.raw(),.all()will still have later columns with the same name overwriting earlier ones.@AndriiSherman sorry for the delay there - the types are released in
4.20240222.0Has it been released already? I would like to run some tests, canβt find this version for types on npm