Postgres update using subselect
by Ryan Guill
Today I learned that postgres allows you to use a subselect in an update statement using a special syntax. This allows you to update a record from other data in the system easily (without remembering the weird update-with-join syntax) or to have an update syntax that more closely resembles an insert statement. For example:
The subselect can be any query, just return your columns in the same order as the column list you provide. Here is the relevant documentation if you want to read further: https://www.postgresql.org/docs/current/static/sql-update.html
Subscribe via RSS