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 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 Python PostgreSQL - Select Data In this article, we are going to see how to use select data using Python in PostgreSQL and psycopg2. Installation Open the command prompt and write the command given below. pip install psycopg2 SELECT statement is used to retrieve the required details of an existing table in PostgreSQL. The data tha 3 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 Python SQLite - Update Data In this article, we will discuss how we can update data in tables in the SQLite database using Python - sqlite3 module. The UPDATE statement in SQL is used to update the data of an existing table in the database. We can update single columns as well as multiple columns using UPDATE statement as per 7 min read Connecting PostgreSQL with SQLAlchemy in Python In this article, we will discuss how to connect PostgreSQL with SQLAlchemy in Python. In order to connect with any Database management system, it is essential to create an engine object, that serves as a central source of connection by providing a connection pool that manages the database connection 3 min read Dynamically Update Multiple Rows with PostgreSQL and Python In this tutorial, we will explore how to dynamically update multiple rows in a PostgreSQL database using Python. By the end of this tutorial, you'll have a solid understanding of how to write efficient Python code that interacts with PostgreSQL to update multiple rows in a database. We'll cover topi 3 min read Python | Database management in PostgreSQL PostgreSQL is an open source object-relational database management system. It is well known for its reliability, robustness, and performance. PostgreSQL has a variety of libraries of API (Application programmable interface) that are available for a variety of popular programming languages such as Py 6 min read Like