2

I'm trying to insert data using psycopg2 into postgres. Here is the psuedo code I have. It seems to run without error but when I use navicat to check, it doesn't seem to update in the database. I did restart navicat to be sure.

conn = psycopg2.connect("dbname=dbname user=username password = ****  host='localhost'")
cur = conn.cursor()

Here I tried a straight execute and a mogrify.

cur.mogrify("""INSERT INTO database (date, id) VALUES (now(), %s );""" % (user,))
cur.execute

I also tried this instead of the mogrify

cur.execute("""INSERT INTO database (date, id) VALUES (now(), %s );""" % (user,))

I can query a select statement but insert doesn't seem to be working.

1
  • Did you execute commit after insert? Commented Aug 27, 2016 at 5:14

1 Answer 1

4

commit the data?

conn.commit()
Sign up to request clarification or add additional context in comments.

3 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
@JulienBernu i thought its only possible answer. sorry:)
Just for clarification, after executing you still need to commit the data using the function conn.commit()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.