Cannot join tables where the columns name are the same.

If you do then the join table will overwrite the from table. it is really frustrating
19 Replies
WcaleNieWolny
WcaleNieWolny11mo ago
did you ever solve this?
PizzaConsole
PizzaConsole11mo ago
There is a work around use the sql`` raw where you need to name your columns differently
WcaleNieWolny
WcaleNieWolny11mo ago
Omg thanks so much I was stuck with this
Angelelz
Angelelz11mo ago
No need to use raw sql I think. You just need to specify the columns that you're selecting explicitly.
PizzaConsole
PizzaConsole11mo ago
If the column names are the same then it has a fit
WcaleNieWolny
WcaleNieWolny11mo ago
the problem is a bit more complicated. It's a problem with D1 itself but the extra abstraction drizzle provides made it difficult to track down. I was recommended to alias the selected columns in a way that would not collide for each other. Turns out drizzle does not have a way to easily alias select so I ended up with this monstrosity
No description
WcaleNieWolny
WcaleNieWolny11mo ago
It would be nice if this could have been avoided all together. That is not at all a problem with the postgress-js backend I could create an issue with a more detailed reproductions steps
Angelelz
Angelelz11mo ago
I think I saw one
PizzaConsole
PizzaConsole11mo ago
Bingo, thanks for detailing it out 🎉
WcaleNieWolny
WcaleNieWolny11mo ago
But honestly my experience with drizzle sqlite was horrible. I had to do this mess and I had to write my own boolean type
Angelelz
Angelelz11mo ago
GitHub
[BUG]: Broken shifted columns with leftJoin and same column name (o...
What version of drizzle-orm are you using? 0.25.4 What version of drizzle-kit are you using? 0.17.6 Describe the Bug I got broken results with leftJoin with same columns. Details My schema (partial...
WcaleNieWolny
WcaleNieWolny11mo ago
Yes, very much Although I heard on d1 support discord that this is intended (this overwrite, or at least that is “not specific to d1”)
PizzaConsole
PizzaConsole11mo ago
Would it be a libsql thing then? Like does Turso have the same behavior? Curious on the boolean type thing.
WcaleNieWolny
WcaleNieWolny11mo ago
Can drizzle perhaps remap this automatically as I did to fix this? Not the ideal solution, but better the what i did
PizzaConsole
PizzaConsole11mo ago
Based on the PR, it could be D1 specific. Rather it appears that they intentionally let it overwrite https://github.com/cloudflare/workerd/pull/911/files
PapaFinn
PapaFinn11mo ago
I feel like I don’t fully understand the issue. Did something like the following not work for you? const firstAlias = aliasedTable(myTable, "firstAlias") const secondAlias = aliasedTable(myTable, "secondAlias") const fetchedData = drizzleClient .select({ first: getTableColumns(firstAlias), second: getTableColumns(secondAlias) }) .from(myTable) .innerJoin(firstAlias, eq(firstAlias.someColumn, someValue)) .leftJoin(secondAlias, eq(secondAlias.someColukn, someOtherValue)) Sorry for mobile formatting 😅
PapaFinn
PapaFinn11mo ago
No description
PizzaConsole
PizzaConsole11mo ago
that did not work for me
Angelelz
Angelelz11mo ago
Could you please share your findings and workaround in that issue?
Want results from more Discord servers?
Add your server