drizzle-team / drizzle-team/drizzle-orm
[BUG]: onConflictDoUpdate doesn't work with jsonb target
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
0.41.0
### What version of `drizzle-kit` are you using?
0.30.6
### Other packages
_No response_
### Describe the Bug
I am having a schema like
```
function extraJsonFieldDeep(
column: PgExtraConfigJson,
keys: Array,
): any {
return sql.raw(`("${column.name}" #>> '{${(keys as string[]).join(',')}}')`);
};
export const articleTable = pgTable(
'article',
{
id: uuid().primaryKey().defaultRandom(),
data: jsonb(),
},
(table) => [
uniqueIndex('doi_idx').on(extraJsonFieldDeep(table.data, ['doi'])),
],
);
```
so there is a unique index on data->>'doi'
now when I am trying to insert with onConflictDoUpdateI cannot make it work no matter what i've tried e.g.
```
await db.insert(articleTable)
.values({
data: someData,
}).onConflictDoUpdate({
target: sql`${articleTable.data} ->> 'doi'` as any,
set: {
data: sql`${articleTable.data} || ${someData}`,
},
})
```
the above fails with " error: column "undefined" does not exist"
Contributor guide
Assessment
This issue has not been assessed yet.