Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
231 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...