postgresqlHow do I use a SELECT statement to update a PostgreSQL table?
To update a PostgreSQL table using a SELECT statement, you must use the UPDATE
command. The syntax is as follows:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
For example, if you wanted to update the name
column of the users
table to John
for all records with an id
of 1
, you could use the following query:
UPDATE users
SET name = 'John'
WHERE id = 1;
This would update the name
column of the users
table to John
for all records with an id
of 1
.
The parts of this query are as follows:
UPDATE
- the keyword used to inform the database that the query will be an update queryusers
- the name of the table to be updatedSET
- the keyword used to inform the database of the columns and values to be updatedname = 'John'
- the column and value to be updatedWHERE
- the keyword used to inform the database of the condition that must be met in order for the update to take placeid = 1
- the condition that must be met in order for the update to take place
For more information on the UPDATE
statement, see the PostgreSQL Documentation.
More of Postgresql
- How can I use PostgreSQL XML functions to manipulate XML data?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I set a PostgreSQL interval to zero?
- How do I use PostgreSQL with Qt?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I use PostgreSQL's "zero if null" feature?
- How can I integrate PostgreSQL with Yii2?
- How can I use PostgreSQL with YAML?
See more codes...