Postgresql table update

I updated the database table using postgresql from python. My code was

import psycopg2
connection=psycopg2.connect("dbname=homedb user=ria")
cursor=connection.cursor()
l_dict= {'licence_id':1}
cursor.execute("SELECT * FROM im_entry.usr_table")
rows=cursor.fetchall()

for row in rows:
   i=i+1
   p = findmax(row)
   #print p
   idn="id"
   idn=idn+str(i)


   cursor.execute("UPDATE im_entry.pr_table SET (selected_entry) = ('"+p+"') WHERE  image_1d ='"+idn+"'")
   print 'DATABASE TO PRINT'
cursor.execute("SELECT * FROM im_entry.pr_table")
rows=cursor.fetchall()
for row in rows:
    print row   

An updated table has appeared

But when I show the updated psql table as homedb = # SELECT * FROM im_entry.pr_table; I got an empty table being displayed ... is something wrong ??? Please help me

+3
source share
1 answer

You are probably not making a transaction, i.e. you need connection.commit()after all your updates.

There are various settings that you can set to the isolation level, for example. autocommit, so you do not need to enter commits yourself. See, for example, How to do database transactions using psycopg2 / python db api?

+7
source

All Articles