Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psycopg2 (insert, update) writing problem

I can send select queries with any problem but when I send update and insert queries it start to wait the thread and don't respond anymore. I couldn't be sure but it seems like a loop.

I know we must use "commit()" for applying changes but it doesn't work.

Here is my code:

import psycopg2
conn = psycopg2.connect("dbname='test' user='postgres' host='localhost' password='xx");
cursor = conn.cursor()
cursor.execute("UPDATE recording SET rank = 10 WHERE id = 10;")
conn.commit()
cursor.close ()
like image 404
burak emre Avatar asked Sep 18 '11 00:09

burak emre


2 Answers

It is most likely a lock in the database, with thread/processes trying to update the same record.

like image 185
piro Avatar answered Oct 05 '22 11:10

piro


import psycopg2

conn = psycopg2.connect(
       database="dbasename",user="username",
       password='your_password',host='web_address',
       port='your_port')
cursor = conn.cursor()
cursor.execute(
  "UPDATE table_name SET update_column_name=(%s)"
  " WHERE ref_column_id_value = (%s)", 
  ("column_name","value_you_want_to_update",));
conn.commit()
cursor.close()

You did not format your execute statement correctly.

like image 35
jdeyrup Avatar answered Oct 05 '22 12:10

jdeyrup