Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Drizzle ORM · Module

.set

.set() defines the column assignments for a Drizzle ORM update query. It accepts schema-column keys with values or SQL expressions, and can be combined with conditions and returning clauses.

How it works

.set() supplies the column-value assignments for an update query. Pass an object whose keys correspond to schema columns; values may be ordinary data or SQL expressions, and the completed update can be narrowed with clauses such as .where() or extended with .returning().

Syntax

db.update(table).set({ column: value })

Parameters

NameTypeDescription
setRecord<keyof TTable, value | SQL>An object mapping schema column names to replacement values or SQL expressions.

Returns

An update query builder; execution returns the database driver's update result, while supported dialects can use .returning() to retrieve updated rows or projections.

Key points

  • Values in the assignment object are parameterized automatically by Drizzle.
  • A property can contain a SQL expression when the new value should be computed by the database.
  • PostgreSQL-style updates can chain .returning() to retrieve selected values from changed rows.
  • For MySQL and SingleStore update builders, .limit() can restrict the number of affected rows.
  • MySQL and SingleStore update builders support .orderBy() for ordering rows considered by the update.

Common mistakes

  • An undefined property is skipped rather than written; use null when the intended database value is NULL.
  • Use schema column keys in the update object so the assignments correspond to actual database columns.

Example: Update a user's column

import { eq } from "drizzle-orm";
import { users } from "./schema";

await db.update(users)
  .set({ name: "Mr. Dan" })
  .where(eq(users.name, "Dan"));

Updates the matching user's name; the WHERE clause limits which rows are changed.

When to use it

Targeted updates

Change selected fields on rows matching a condition.

SQL expressions

Set timestamps, counters, or other values calculated by the database.

Returning updated data

Retrieve identifiers or projections from changed rows where the dialect supports it.

Interview questions

QWhat does .set() do in an update query?

.set() receives an object containing the columns to change and their new values. In db.update(users).set({ name: "Mr. Dan" }), Drizzle creates the assignment for name.

Follow-up: How would you assign a database-computed value? Pass a SQL expression, such as sql\NOW()\, as the property value.

QHow does Drizzle handle values passed to .set()?

Values supplied to .set() are parameterized automatically. This keeps ordinary values separate from the generated SQL rather than interpolating them directly.

Follow-up: How can a value be computed from an existing column? Use a SQL value such as sql\${table.counter} + 1\.

QWhat happens when a .set() value is undefined?

A property with undefined is ignored, so it does not overwrite the column. To write SQL NULL, provide null explicitly.

Follow-up: What should be used when an update should affect only selected rows? Add a .where() condition to constrain the update.

  • update
  • where
  • returning
  • from
  • sql
  • limit
  • orderBy

Source: Drizzle ORM - Update. Checked 2026-10-16.