drizzle-team / drizzle-team/drizzle-orm

[BUG]: onConflictDoUpdate doesn't work with jsonb target

Open
#4,427 2 comments 0 reactions 0 assignees View on GitHub
bug db/postgres qb/crud
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.