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

Drizzle ORM · Module

db.update

Drizzle’s update builder changes rows in a table using schema-typed values and an optional predicate. It supports parameterized values, SQL expressions, PostgreSQL returning, and dialect-specific clauses such as limit and orderBy.

How it works

Call update with a table, provide column values through set, and narrow affected rows with where. Values are parameterized automatically; PostgreSQL can return updated rows with returning, while SQL expressions can be supplied as update values.

Syntax

await db.update(table).set(values).where(condition);

Parameters

NameTypeDescription
tableTableTarget table whose rows will be modified.
set(values)Update valuesObject mapping schema column names to replacement values or SQL expressions.
where(condition)SQL conditionPredicate selecting rows to modify.

Returns

An update query result; PostgreSQL can additionally return updated rows with returning().

Key points

  • Pass a schema-shaped object to update so its properties identify valid database columns.
  • Drizzle parameterizes set values automatically rather than requiring manual placeholders.
  • A set value may be a SQL expression when the new value should be computed by the database.
  • PostgreSQL supports retrieving updated rows through the returning clause.
  • Use limit to cap the number of rows affected where the dialect supports it.
  • orderBy controls update ordering where the database dialect supports an ordered update.

Common mistakes

  • undefined does not clear a column; use null when the intended database value is NULL.

Example: Update matching rows

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

const updated = await db
  .update(users)
  .set({ name: 'Mr. Dan' })
  .where(eq(users.name, 'Dan'))
  .returning({ updatedId: users.id });

console.log(updated);

Updates matching users and returns their IDs in PostgreSQL.

When to use it

Apply a conditional update

Change selected records

Set a column with a SQL expression

Use a database-side calculation or function

Return updated PostgreSQL rows

Obtain identifiers or fields after modification

Interview questions

QWhat is the basic Drizzle update pattern?

Use db.update(table).set(values).where(condition). The set object uses schema column names, and supplied values are parameterized automatically.

Follow-up: How can an update return changed rows? In PostgreSQL, append returning with the selected columns.

QWhat can be supplied to set()?

The keys passed to set must correspond to columns in the database schema. SQL expressions can also be used as values, such as sqlNOW() for a timestamp.

Follow-up: How would you update a timestamp using the database clock? Set the timestamp column to sqlNOW().

QHow do you retrieve data from updated rows?

A PostgreSQL update can append returning to retrieve updated data, including a projection such as returning({ updatedId: users.id }). Use where to control which rows are changed.

Follow-up: What is the safety concern with returning? It retrieves affected rows but does not restrict which rows are modified; the predicate still belongs in where.

  • eq
  • sql
  • returning
  • limit
  • orderBy
  • from

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