postgresqlHow do I update a record in PostgreSQL?
Updating a record in PostgreSQL is done using the UPDATE
statement. The UPDATE
statement is used to modify existing records in a table.
The syntax for the UPDATE
statement is as follows:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Where table_name
is the name of the table to update, column1
, column2
, etc. are the column names to update, value1
, value2
, etc. are the new values to set for the columns, and condition
is the condition that must be met for the records to be updated.
For example, to update the name
column in the users
table for the user with id
of 4, the following statement could be used:
UPDATE users
SET name = 'John Doe'
WHERE id = 4;
Code explanation
UPDATE users
- specifies the table to updateSET name = 'John Doe'
- sets thename
column to the specified valueWHERE id = 4
- specifies the condition that must be met for the records to be updated
Helpful links
More of Postgresql
- How do I parse XML data using PostgreSQL?
- How can Zalando use PostgreSQL to improve its software development?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL and ZFS together?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I use PostgreSQL with YAML?
See more codes...