Tanmay Bhatnagar
Tanmay Bhatnagar

Reputation: 2470

Unable to update PostgrSQL table using psycopg2

I am trying to update a table using psycopg2 library since I need to bulk update that column. When I run

tr_cursor.execute("UPDATE <table-name> set <column-name> = 'KR' where id = 21;")

The command runs in < 1 second but it DOES NOT update the table. When I run the same command in datagrip it takes more than 4minutes to run (I stopped it at 4min, did NOT let it run fully. Just wanted to check the time required). What am I doing wrong here? Please ask for any further info that is required

Upvotes: 1

Views: 50

Answers (1)

Michal T
Michal T

Reputation: 611

I'm guessing you might be missing a conn.commit() atter your UPDATE statement. conn being what you created with the conn=psycopg2.connect(... call.

It is the default behavior for all database statements with psycopg. Of course for select you don't need it, as there is nothing to commit. But it is a parameter you can change, check the autocommit option: http://psycopg.org/docs/connection.html#connection.autocommit

Upvotes: 1

Related Questions