Replies: 7 comments 1 reply
-
I've encountered the same thing – doesn't seem that
|
Beta Was this translation helpful? Give feedback.
-
I think you can do it with a subquery. const sq = await select({ id: table.id}) // your subquery here await db.update(tasks).set(...).where(inArray(..., sq.id) |
Beta Was this translation helpful? Give feedback.
-
Bump this, trying to use update from in Postgresql update test as t set
column_a = c.column_a
from (values
('123', 1),
('345', 2)
) as c(column_b, column_a)
where c.column_b = t.column_b; |
Beta Was this translation helpful? Give feedback.
-
Also bump! I had to do a raw sql query for update joins and just got bit by a type error. It would be great if drizzle natively supported update joins. I'm happy to take a look at implementing this myself if the maintainers believe it would be something do-able by an outsider. (To me, naively, it seems like just a matter of being able to add some "join" text after the "update" text in the query - but I am not at all familiar with the drizzle code). Here's a snippet of my code where I have to use raw sql, and where "update join" would be very helpful: await trx.execute(sql`
UPDATE ${TableTransaction} AS t
JOIN ${TableMerkleLeaf} AS ml ON t.id = ml.transaction_id
SET t.state = 'block', t.block_num = ${header.blockNum.n}
WHERE ml.domain = ${domain}
AND ml.block_num = ${header.blockNum.n}
AND ml.order_num <= ${orderNum}
`); |
Beta Was this translation helpful? Give feedback.
-
I see PR with support this |
Beta Was this translation helpful? Give feedback.
-
I too would love to see this turned into a feature request. |
Beta Was this translation helpful? Give feedback.
-
This is normal SQL and I expected it to be possible with Drizzle! I don't think there's a way to do this without a fully-string raw sql query. Of course one can use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm sorry if this has been answered elsewhere, but I couldn't find anything in the docs or discussions.
I am looking to build a query that runs an update with multiple joins, e.g.:
I have landed on the following using
sql
for now:I was hoping to do something like the following but
join
is not available onPgUpdate<PgTableWithColumns<...>>
:Am I missing something obvious, or is this update-with-join not currently possible without raw SQL in Drizzle?
If it isn't currently possible and it's something that is planned/desired, then I would be happy to contribe!
Beta Was this translation helpful? Give feedback.
All reactions