I had to write a quick feed parser using psycopg before and was wondering why stuff didn't save.
Turns out I was missing a very important line at the end... connection.commit() !
A quick example below shows how to use psycopg.
connection = None
cursor = None
# Connect to an existing database
self.connection = psycopg2.connect("dbname=yourdbname user=username host=twigstechtips.blogspot.com")
self.cursor = self.connection.cursor()
if self.cursor is not None:
if self.connection is not None:
def save(self, items):
if self.cursor is None:
raise Exception("Invalid connection to database.")
# Delete existing
self.cursor.execute("DELETE FROM table_name")
# Fill in the new values
for item in items:
sql = "INSERT INTO table_name (id, name, weight) VALUES (%s, %s, %s)"
self.cursor.execute(sql, (item.id, item.title, item.order))
# Write the new info to db
[ Source ]