drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: alias of rows to insert with ON DUPLICATE KEY
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe what you want
From the MySQL [documentation](https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html#:~:text=Beginning%20with%20MySQL%208.0.19,the%20form%20shown%20here%3A) :
> Beginning with MySQL 8.0.19, it is possible to use an alias for the row, with, optionally, one or more of its columns to be inserted, following the VALUES or SET clause, and preceded by the AS keyword. Using the row alias new, the statement shown previously using VALUES() to access the new column values can be written in the form shown here:
```sql
INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS new
ON DUPLICATE KEY UPDATE c = new.a+new.b;
```
At the moment it is possible to use VALUES() with ON DUPLICATE KEY, like
```typescript
await drizzleClient
.insert(foo)
.values([...])
.onDuplicateKeyUpdate({
set: {
bar: sql`VALUES(${foo.bar})`
},
});
```
but this syntax is [deprecated](https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html#:~:text=Note,of%20this%20section.) and could be removed in future version of MySQL:
> Note
> The use of VALUES() to refer to the new row and columns is deprecated beginning with MySQL 8.0.20, and is subject to removal in a future version of MySQL. Instead, use row and column aliases, as described in the next few paragraphs of this section.
Contributor guide
Assessment
This issue has not been assessed yet.