名字很滑稽,使用方法與 pgsql for python使用方式有所不同 ,但都 遵循DB2.0
http://initd.org/psycopg/docs/usage.html 參考文檔
>>> cur.execute("INSERT INTO foo VALUES (%s)", ("bar",)) # correct
注意 %s不能攜帶''字符串定界符;參數tuples必須添加末尾 ,
>>> cur.execute(
... """INSERT INTO some_table (an_int, a_date, a_string)
... VALUES (%s, %s, %s);""",
... (10, datetime.date(2005, 11, 18), "O'Reilly"))
參數數組傳遞方式
>>> cur.execute(
... """INSERT INTO some_table (an_int, a_date, another_date, a_string)
... VALUES (%(int)s, %(date)s, %(date)s, %(str)s);""",
... {'int': 10, 'str': "O'Reilly", 'date': datetime.date(2005, 11, 18)})
參數哈希傳遞方式
cur.execute('insert into table_a values(%s)',(psycopg2.Binary(file.read()),))
插入二進制數據