I ran into a question when trying to use db.query to update some values. The code below returns AttributeError: 'tuple' object has no attribute 'keys', but an almost identical rendition in psycopg2 executes the command correctly. What could be the issue here?
db = dataset.connect('postgresql://my_database')
db = dataset.connect()
db.begin()
db.query('''
UPDATE scrape_log
SET date_scraped=%s, result_count=%s
WHERE start_date=%s AND end_date=%s;
''', (date_scraped, result_count, start_date, end_date))
db.commit()
vs.
conn = psycopg2.connect('postgresql://my_database')
cur = conn.cursor()
cur.execute('''
UPDATE scrape_log
SET date_scraped=%s, result_count=%s
WHERE start_date=%s AND end_date=%s;
''', (date_scraped, result_count, start_date, end_date))
conn.commit()
Now if anyone could kindly let me know if there's a more elegant solution using update, I shall be very grateful. Sorry for what might be a sophomoric question, but for someone new to SQL, this library has made my life so much easier. Thanks so much!
I ran into a question when trying to use
db.query
to update some values. The code below returnsAttributeError: 'tuple' object has no attribute 'keys'
, but an almost identical rendition inpsycopg2
executes the command correctly. What could be the issue here?vs.
Now if anyone could kindly let me know if there's a more elegant solution using
update
, I shall be very grateful. Sorry for what might be a sophomoric question, but for someone new to SQL, this library has made my life so much easier. Thanks so much!