cur.close()Ĭonn.close() Code language: Python ( python ) Updating data example mit() Code language: Python ( python )įinally, close the communication with the PostgreSQL database server by calling the close() method of the cursor and connection objects. If you want to get the number of rows affected by the UPDATE statement, you can get it from the rowcount attribute of the cursor object after calling the execute() method.Īfter that, save the changes to the database permanently by calling the commit() method of the connection object. The second parameter is a list of input values that you want to pass to the UPDATE statement. The first parameter is an SQL statement to be executed, in this case, it is the UPDATE statement. The execute() method accepts two parameters. execute(update_sql, (value1,value2)) Code language: PostgreSQL SQL dialect and PL/pgSQL ( pgsql ) Then, execute the UPDATE statement with the input values by calling the execute() method of the cursor object. cursor() Code language: PostgreSQL SQL dialect and PL/pgSQL ( pgsql ) Next, create a new cursor object by calling the cursor() method of the connection object. The connect() method returns a new connection object. conn = nnect(dns) Code language: Python ( python ) The steps for updating data are similar to the steps for inserting data into a PostgreSQL table.įirst, connect to the PostgreSQL database server by calling the connect() function of the psycopg module. Steps for updating data in a PostgreSQL table using psycopg2 Summary: in this tutorial, you will learn how to update data in a PostgreSQL table from a Python program.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |