import psycopg, time
dsn = 'dbname=dbname user=username'
print "Connecting to %s" % dsn
dbh = psycopg.connect(dsn)
print "Connection successful."
cur = dbh.cursor()
cur.execute("""CREATE TABLE myTable (
mydate DATE,
mytimestamp TIMESTAMP,
mytime TIME,
mystring varchar(30))""")
query = """INSERT INTO myTable VALUES (
%(mydate)s, %(mytimestamp)s, %(mytime)s, %(mystring)s)"""
rows = ( \
{'mydate': psycopg.Date(2009, 12, 25),
'mytimestamp': psycopg.Timestamp(2009, 12, 15, 06, 30, 00),
'mytime': psycopg.Time(6, 30, 00),
'mystring': 'message!'},
{'mydate': psycopg.DateFromTicks(time.time()),
'mytime': psycopg.TimeFromTicks(time.time()),
'mytimestamp': psycopg.TimestampFromTicks(time.time()),
'mystring': None})
cur.executemany(query, rows)
dbh.commit()
dbh.close()