🌐
W3Schools
w3schools.com › postgresql › postgresql_update.php
PostgreSQL - The UPDATE Statement
The UPDATE statement is used to ... Note: Be careful with the WHERE clause, in the example above ALL rows where brand = 'Volvo' gets updated....
🌐
PostgreSQL
postgresql.org › docs › current › sql-update.html
PostgreSQL: Documentation: 18: UPDATE
May 14, 2026 - The sub-query can refer to old values of the current row of the table being updated. ... A table expression allowing columns from other tables to appear in the WHERE condition and update expressions. This uses the same syntax as the FROM clause of a SELECT statement; for example, an alias for the table name can be specified.
🌐
DataCamp
datacamp.com › doc › postgresql › update
PostgreSQL UPDATE
UPDATE employees SET salary = 50000 WHERE employee_id = 123; This example updates the `salary` column to 50,000 for the employee with an `employee_id` of 123.
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › postgresql-update
PostgreSQL UPDATE Statement - GeeksforGeeks
July 12, 2025 - In this example, we will update the last name of an employee whose first name is "Raju." Let's change Raju Kumar to Raju Singh. This ensures that only the row with the matching first name "Raju" is updated, demonstrating the use of the WHERE ...
🌐
TutorialsPoint
tutorialspoint.com › postgresql › postgresql_update_query.htm
PostgreSQL - UPDATE
In PostgreSQL, UPDATE statement is used to modify or change the existing records in a table. You can use WHERE clause with UPDATE statement to update the selected rows. Otherwise, all the rows would be updated.
🌐
TechOnTheNet
techonthenet.com › postgresql › update.php
PostgreSQL: UPDATE Statement
This PostgreSQL UPDATE example would update the first_name to 'Jane' in the contacts table where the contact_id is 35.
🌐
DB Vis
dbvis.com › thetable › the-postgres-update-statement-a-deep-dive
The Postgres UPDATE Statement: A Deep Dive
September 5, 2024 - Omit the WHERE clause in a Postgres UPDATE query to update every row in the table.
🌐
PostgreSQL Tutorial
pgtutorial.com › home › postgresql tutorial › postgresql update statement: updating data in a table
PostgreSQL UPDATE Statement: Updating Data in a Table
January 2, 2025 - UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition RETURNING *;Code language: PostgreSQL SQL dialect and PL/pgSQL (pgsql) The following example uses the UPDATE statement to update the price of the Pixel 7 Pro product to 750 and return the updated row:
🌐
TutorialKart
tutorialkart.com › postgresql › postgresql-update
PostgreSQL UPDATE Query - Examples
November 30, 2020 - ... You can update multiple columns as specified in the syntax given at the starting of this tutorial. We will update age and attendance where id = 3. ... In this PostgreSQL Tutorial, we used UPDATE query on PostgreSQL Table, to update column ...
Find elsewhere
🌐
Neon
neon.com › postgresql › tutorial › update
PostgreSQL UPDATE Statement
UPDATE courses SET published_date = '2020-07-01' WHERE course_id = 2 RETURNING *; ... course_id | course_name | price | description | published_date -----------+----------------------------+--------+----------------------------+---------------- ...
🌐
Mytechmantra
mytechmantra.com › home › postgresql › postgresql update statement tutorial
PostgreSQL UPDATE Statement Tutorial with Examples & Best Practices - MyTechMantra.com
January 6, 2026 - PostgreSQL Update Single Column Example in Employees Table ... Suppose an employee named Alice moves to the HR department. UPDATE employees SET department = 'HR' WHERE name = 'Alice'; ... The query targets the employees table.
Top answer
1 of 16
1315

The UPDATE syntax is:

[ WITH [ RECURSIVE ] with_query [, ...] ]
UPDATE [ ONLY ] table [ [ AS ] alias ]
    SET { column = { expression | DEFAULT } |
          ( column [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...]
    [ FROM from_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

In your case I think you want this:

UPDATE vehicles_vehicle AS v 
SET price = s.price_per_vehicle
FROM shipments_shipment AS s
WHERE v.shipment_id = s.id 

Or if you need to join on two or more tables:

UPDATE table_1 t1
SET foo = 'new_value'
FROM table_2 t2
    JOIN table_3 t3 ON t3.id = t2.t3_id
WHERE
    t2.id = t1.t2_id
    AND t3.bar = True;
2 of 16
316

The answer of Mark Byers is the optimal in this situation. Though in more complex situations you can take the select query that returns rowids and calculated values and attach it to the update query like this:

with t as (
  -- Any generic query which returns rowid and corresponding calculated values
  select t1.id as rowid, f(t2, t2) as calculatedvalue
  from table1 as t1
  join table2 as t2 on t2.referenceid = t1.id
)
update table1
set value = t.calculatedvalue
from t
where id = t.rowid

This approach lets you develop and test your select query and in two steps convert it to the update query.

So in your case the result query will be:

with t as (
    select v.id as rowid, s.price_per_vehicle as calculatedvalue
    from vehicles_vehicle v 
    join shipments_shipment s on v.shipment_id = s.id 
)
update vehicles_vehicle
set price = t.calculatedvalue
from t
where id = t.rowid

Note that column aliases are mandatory otherwise PostgreSQL will complain about the ambiguity of the column names.

🌐
w3resource
w3resource.com › PostgreSQL › snippets › postgresql-update-from-select.php
PostgreSQL Update from Select with Examples and Explanation
December 31, 2024 - Learn PostgreSQL update from select syntax with examples. Simplify data updates between tables using efficient queries. Step-by-step guide included.
🌐
CommandPrompt Inc.
commandprompt.com › education › how-to-use-update-query-in-postgresql
How to Use Update Query in PostgreSQL — CommandPrompt Inc.
August 2, 2022 - Example: How to Update a single row in PostgreSQL? We have an existing table named “team_members”. We will utilize the UPDATE query to update a specific row of the “team_members” table.
🌐
Medium
medium.com › @mnu › update-a-postgresql-table-using-a-with-query-648eefaae2a6
Update a PostgreSQL table using a WITH query | by m4nu56 | Medium
October 10, 2020 - Update a PostgreSQL table using a WITH query I often need to update a table using values from a different table and most of the time the quickest and also dirtiest solution is simply to do a …
🌐
Scaler
scaler.com › home › topics › postgresql › postgresql update query
PostgreSQL UPDATE Query - Scaler Topics
January 29, 2024 - The above query will update the salary column for the employee with employee_id equal to 101 to the new value of 60000. In PostgreSQL, the RETURNING clause is an optional part of the UPDATE query that allows you to retrieve the modified data ...
🌐
SQLS*Plus
sqlsplus.com › postgresql-update-statement
PostgreSQL UPDATE statement - SQLS*Plus
If you want to update multiple columns, you can do so by separating the column/value pairs with commas. In this PostgreSQL example of UPDATE, the value of the city will be changed to ‘Abilene’ and the state will be changed to ‘Beaumont’ where contact_id is greater than or equal to 200.
Published   September 8, 2020
🌐
TigerData
tigerdata.com › learn › using-postgresql-update-with-join
Using PostgreSQL UPDATE With JOIN | Tiger Data
December 10, 2025 - Important note: When using UPDATE ... times. In this example, if a product has multiple inventory records with quantity = 0, the same product will be updated once for each matching inventory row....
🌐
Tutorial Teacher
tutorialsteacher.com › postgresql › update-data
PostgreSQL Update Data in a Table
Use the WHERE clause with the UPDATE statement and specify a primary key value to update a single row in the table. For example, the following UPDATE statement will update an email of an employee whose emp_id=1.