PostgreSQL Python – Update Data in Table
In this article, we are going to see how to update existing data in PostgreSQL tables using the pyscopg2 module in Python.
In PostgreSQL, the UPDATE TABLE with where clause is used to update the data in the existing table from the database.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Syntax: UPDATE <table_name> SET column1 = value1, column2 = value2,….. WHERE [condition]
To execute any SQL query execute() function is called with the SQL command to be executed as a parameter.
Syntax: execute(SQL command)
Table for demonstration:
Below is the implementation:
Table after updating the record:
As we can see state name has been updated to Haryana where the name is Radha. It means the operation has been successfully completed.