ich habe eine ganz blöde frage

und zwar wollte ich werte in eine Datenbank schreiben. (siehe erster Programmteil)
dies funktioniert sehr gut, da ich absoluter Python Neuling bin, hätte ich gedacht, dass das update so ähnlich funktioniert. (siehe zweiter Programmteil)
Leider funktioniert dies so nicht, es kommt folgende Fehlermeldung:
Traceback (most recent call last):
File "mc.py", line 116, in <module>
adcs(netio)
File "mc.py", line 97, in adcs
cur.execute('UPDATE PollinAVR SET (ID, State, time) values(%s, %s, %s)', ("ADC1", ADC1, CURRENT_TIMESTAMP))
psycopg2.ProgrammingError: syntax error at or near "values"
LINE 1: UPDATE PollinAVR SET (ID, State, time) values('ADC1', '424',...
^
Außerdem bin ich mir sicher dass man sowas noch schöner machen kann.
wie date ich eine Leere Tabelle ab? müssen da Werte drin stehen oder geht das auch mit leeren?
vielen Dank
Code: Alles auswählen
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('insert into PollinAVR (ID, State,time) values(%s, %s, %s)', ("ADC1", ADC1, CURRENT_TIMESTAMP))
conn.commit()
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('insert into PollinAVR (ID, State,time) values(%s, %s, %s)', ("ADC2", ADC2, CURRENT_TIMESTAMP))
conn.commit()
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('insert into PollinAVR (ID, State,time) values(%s, %s, %s)', ("ADC3", ADC3, CURRENT_TIMESTAMP))
conn.commit()
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('insert into PollinAVR (ID, State,time) values(%s, %s, %s)', ("ADC4", ADC4, CURRENT_TIMESTAMP))
conn.commit()
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('UPDATE PollinAVR SET (ID, State, time) values(%s, %s, %s)', ("ADC1", ADC1, CURRENT_TIMESTAMP))
conn.commit()
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('UPDATE PollinAVR SET (ID, State, time) values(%s, %s, %s)', ("ADC2", ADC2, CURRENT_TIMESTAMP))
conn.commit()
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('UPDATE PollinAVR SET (ID, State, time) values(%s, %s, %s)', ("ADC3", ADC3, CURRENT_TIMESTAMP))
conn.commit()
CURRENT_TIMESTAMP = datetime.now()
print CURRENT_TIMESTAMP
cur.execute('UPDATE PollinAVR SET (ID, State, time) values(%s, %s, %s)', ("ADC4", ADC4, CURRENT_TIMESTAMP))
conn.commit()