python - changes don't seem to take affect in Postgres DB -
whenever run python scripts interact postgresql database, don't seem have effect. don't error, , in code seems execute fine (e.g., prints after db operations show expected), when @ database later, don't see evidence code ran. example, have following code:
def testdeletewins(): deletewins() print "old wins deleted." def deletewins(): db = connect() c = db.cursor() c.execute("delete wins;") print "task done!" def connect() print"connected" return psycopg2.connect("dbname=project")
if run testdeletewins()
see "task done!" print out, none of records removed wins
table. need changes take effect in db?
by default psycopg2
has cursor
's not autocommit. in deletewins
add db.commit()
after c.execute
. deletewins
like:
def deletewins(): db = connect() c = db.cursor() c.execute("delete wins;") db.commit() print "task done!"
Comments
Post a Comment