missing FROM-clause entry for table "subquery"

So I am trying to update a row while using a subquery for it but getting erro all the time
No description
6 Replies
Mario564
Mario5643mo ago
You need to use a with clause, as so:
const subquery = db.$with('subquery').as(/* your sq, without the final `.as()` */);
await db.with(subquery)./* the rest as usual*/;
const subquery = db.$with('subquery').as(/* your sq, without the final `.as()` */);
await db.with(subquery)./* the rest as usual*/;
maverickdoge
maverickdogeOP3mo ago
@Mario564 So I did that but now I am getting error "missing FROM-clause entry for table "subquery""
No description
Mario564
Mario5643mo ago
Oh, that means that you need to add a from clause pointed to the subquery. Issue is that currently, Drizzle doesn't support from clause in update statements. You can try this instead:
// No with clause
await db
.update(addresses)
.set({ ... })
.where(eq(addresses.id, sql`(${subquery})`));
// No with clause
await db
.update(addresses)
.set({ ... })
.where(eq(addresses.id, sql`(${subquery})`));
This uses a subquery directly embedded into the comparison. It's not super clean but it's an alternative from using the from clause.
DoomD_007
DoomD_0073mo ago
is there plans on adding from clause in update query?
Mario564
Mario5643mo ago
Yes, I'm actually working on it, but can't be sure when it'll be in a release since there's a lot of other things that are being worked on
DoomD_007
DoomD_0073mo ago
thnx
Want results from more Discord servers?
Add your server