python - .execute('INSERT ...') does not actually insert data into table -


warning: brain fart imminent

i've been @ bit now, , i'm guessing "i'm tired, can't through head" type of issue i'm hoping break down me..

i'll explain backwards because makes more sense..

i verify contents of table doing:

select distinct date(time) unique_dates reports; 

i'm expecting:

2014-06-17 2014-06-16 

but 17 missing..
naturally check query_string doing:

import psycopg2 database = psycopg2.connect(dbname=database, user=user, password=password, database=database) cursor = database.cursor() query_string = b"insert reports (time) values " + b','.join(cursor.mogrify('(%s)', value) value in values) + b';') print(query_string) cursor.execute(query_string) 

resulting in:

b"insert reports(time) values ('2014-06-17 10:00:08'),('2014-06-17 14:00:05');" 

and no error messages.
, lo , behold.. if query:

select * pg_stat_activity; 

the insert shows up. (all tho @ random times considering how fast query fly <idle> state.. it's there)

but again, it's not in database.. how possible? if take command , execute in psql on own sure enough it's inserted..

it makes no sense.. make sense if pid performing executions on database, can't there because again last select shows no active sessions, they're idle..

you need commit transaction:

connection.commit() 

see transactions control section of psycopg2 documentation.

psql operates in different transaction mode; auto-commits statements. psql documentation:

autocommit
when on (the default), each sql command automatically committed upon successful completion. postpone commit in mode, must enter begin or start transaction sql command. when off or unset, sql commands not committed until explicitly issue commit or end.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -