PostgreSQL UPDATE Query
The UPDATE Command allows one to manipulate the existing records in a table.You can use the WHERE clause with the UPDATE query to update the selected rows.
PostgreSQL UPDATE Syntax:
The syntax is as follows:
UPDATE table_name SET column1 = value1, column2 = value2 [WHERE condition];
In this, the value of column 1 will be modify to value 1, column 2 to value 2 and similar columnsN to valueN.You can add N number of conditions using AND or OR operators.
UPDATE Example :
Consider the STUDENT table is having the following records
ID | NAME | AGE | ADDRESS |
---|---|---|---|
1 | Rahul | 20 | Mysore |
2 | Kartik | 19 | Delhi |
3 | Nidhi | 21 | Udaipur |
4 | Prateek | 19 | Jaipur |
5 | Jugal | 20 | Mumbai |
6 | Abhi | 19 | Mumbai |
The following is an example, which would update AGE for a STUDENT, whose ID is 3
lfcdb=# UPDATE STUDENT SET AGE = 22 WHERE ID = 3;
All the above statements would create the following records in STUDENT table
ID | NAME | AGE | ADDRESS |
---|---|---|---|
1 | Rahul | 20 | Mysore |
2 | Kartik | 19 | Delhi |
3 | Nidhi | 22 | Udaipur |
4 | Prateek | 19 | Jaipur |
5 | Jugal | 20 | Mumbai |
6 | Abhi | 19 | Mumbai |
Visit :
Discussion