PostgreSQL Python - Update Data in Table Last Updated : 23 Sep, 2021 Comments Improve Suggest changes Like Article Like Report 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. 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: Python3 # importing psycopg2 module import psycopg2 # establishing the connection conn = psycopg2.connect( database="postgres", user='postgres', password='password', host='localhost', port='5432' ) # creating cursor object cursor = conn.cursor() # creating table sql = '''CREATE TABLE Geeky( id SERIAL NOT NULL, name varchar(20) not null, state varchar(20) not null )''' cursor.execute(sql) # inserting values in it cursor.execute('''INSERT INTO Geeky(name , state)\ VALUES ('Babita','Bihar')''') cursor.execute( '''INSERT INTO Geeky(name , state)\ VALUES ('Anushka','Hyderabad')''') cursor.execute( '''INSERT INTO Geeky(name , state)\ VALUES ('Anamika','Banglore')''') cursor.execute('''INSERT INTO Geeky(name , state)\ VALUES ('Sanaya','Pune')''') cursor.execute( '''INSERT INTO Geeky(name , state)\ VALUES ('Radha','Chandigarh')''') # query to update the existing record # update state as Haryana where name is Radha sql1 = "UPDATE Geeky SET state = 'Haryana' WHERE name = 'Radha'" cursor.execute(sql1) # Commit your changes in the database conn.commit() # Closing the connection conn.close() 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. Comment More infoAdvertise with us Next Article PostgreSQL Python - Update Data in Table A annulata2402 Follow Improve Article Tags : Python Python PostgreSQL Python Pyscopg2 Practice Tags : python Similar Reads Python PostgreSQL - Update Table In this article, we will see how to Update data in PostgreSQL using python and Psycopg2. The update command is used to modify the existing record in the table. By default whole records of the specific attribute are modified, but to modify some particular row, we need to use the where clause along wi 2 min read PostgreSQL - Create Tables in Python Creating tables in PostgreSQL using Python is an essential skill for developers working with databases. This article will explore the process of creating new tables in the PostgreSQL database using Python.Why Create PostgreSQL Tables with Python?Using Python to create PostgreSQL tables is beneficial 4 min read PostgreSQL - Create table using Python Creating tables in a PostgreSQL database using Python is a common task for developers working with databases. This process involves defining the structure of your data and ensuring that your database is optimized for efficient storage and retrieval. In this article, we will walk through the steps of 3 min read PostgreSQL Python - Querying Data Psycopg2 acts as a bridge between Python applications and PostgreSQL databases. Widely employed in diverse Python systems, from web applications to data analysis tools and other software projects, Psycopg2 enables developers to execute queries and manipulate data stored in PostgreSQL databases. In t 5 min read Python PostgreSQL - Delete Data In this article, we are going to see how to delete data in tables from PostgreSQL using pyscopg2 module in Python. In PostgreSQL, DELETE TABLE is used to delete the data in the existing table from the database. It removes table definition and all associated data, indexes, rules, triggers, and constr 2 min read Like