UPDATE (Update Rows)

Last updated: 2026-11-04

UPDATE (Update Rows)

UPDATE modifies rows that already exist. It picks target rows with WHERE and assigns new values with SET, where the new value may be an expression computed from the old one (say amount * 1.1). UPDATE can also read from other tables via a FROM clause and return the modified rows with RETURNING.

Kindcommand
Example LanguageSQL

📝 Syntax

UPDATE <table> [AS <alias>]
SET <column> = <expression>, ...
[FROM <other table> [, ...]]
[WHERE <condition>]
[RETURNING <column or expression>]

⚙️ Parameters

SETThe columns to update and their new values
WHEREFilters the rows to update
FROMOther tables that supply the new values
RETURNINGReturns the updated rows

Returns:The number of affected rows; with RETURNING, the updated rows are returned as well.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

DROP TABLE
CREATE TABLE
INSERT 0 3
UPDATE 2
id | customer | amount  | bonus 
---+----------+---------+-------
 1 | Alice    | 1100.00 | 100.00
 2 | Bob      |  550.00 |  50.00

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QHow do I compute a value from the old row in a single UPDATE?
AJust write amount = amount * 1.1: the right-hand side reads the old value and the left-hand side stores the new one.
QDoes UPDATE lock the whole table?
ANot the whole table, but the updated rows take row-level locks that make concurrent updates to the same rows wait. With an index, only the matched rows are touched.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏