Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/content/docs/guides/upsert.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ This is how you can do it:
.values(values)
.onConflictDoUpdate({
target: users.id,
set: { lastLogin: sql.raw(`excluded.${users.lastLogin.name}`) },
set: { lastLogin: sql.raw(`excluded."${users.lastLogin.name}"`) },
});
```

Expand All @@ -83,7 +83,7 @@ This is how you can do it:
(1, '2024-03-15T22:29:06.679Z'),
(2, '2024-03-15T23:29:06.679Z'),
(3, '2024-03-16T00:29:06.679Z')
on conflict ("id") do update set last_login = excluded.last_login;
on conflict ("id") do update set last_login = excluded."last_login";
```
</CodeTab>
```ts copy
Expand Down Expand Up @@ -117,7 +117,7 @@ Drizzle has simple and flexible API, which lets you easily create custom solutio

return columns.reduce((acc, column) => {
const colName = cls[column].name;
acc[column] = sql.raw(`excluded.${colName}`);
acc[column] = sql.raw(`excluded."${colName}"`);

return acc;
}, {} as Record<Q, SQL>);
Expand Down Expand Up @@ -156,7 +156,7 @@ Drizzle has simple and flexible API, which lets you easily create custom solutio
(1, '2024-03-16T15:44:41.141Z', true),
(2, '2024-03-16T16:44:41.141Z', true),
(3, '2024-03-16T17:44:41.141Z', true)
on conflict ("id") do update set last_login = excluded.last_login, active = excluded.active;
on conflict ("id") do update set last_login = excluded."last_login", active = excluded."active";
```
</CodeTab>
```ts copy
Expand Down Expand Up @@ -208,8 +208,8 @@ If you want to implement upsert query with `where` clause for `update` statement
lastUpdated: new Date(),
};

const excludedPrice = sql.raw(`excluded.${products.price.name}`);
const excludedStock = sql.raw(`excluded.${products.stock.name}`);
const excludedPrice = sql.raw(`excluded."${products.price.name}"`);
const excludedStock = sql.raw(`excluded."${products.stock.name}"`);

await db
.insert(products)
Expand All @@ -232,8 +232,8 @@ If you want to implement upsert query with `where` clause for `update` statement
insert into products ("id", "title", "stock", "price", "last_updated")
values (1, 'Phone', 10, '999.99', '2024-04-29T21:56:55.563Z')
on conflict ("id") do update
set stock = excluded.stock, price = excluded.price, last_updated = excluded.last_updated
where (stock != excluded.stock or price != excluded.price);
set stock = excluded."stock", price = excluded."price", last_updated = excluded."last_updated"
where (stock != excluded."stock" or price != excluded."price");
```
</CodeTab>

Expand Down