0
我已成功使用psycopg2模塊獲得從Python中的連接,我想有以下四列數據插入到「監考」表:psycopg2 - 插入 - tsrange與性格不同類型
course_id = "651" # Character varying(6)
date = "[2015-08-22 10:00:00,2015-08-22 12:00:00)" #tsrange
room_id = "d2" #text
duration = 150 #smallint
日期字段當前格式化爲字符串。我知道「datetime」模塊;然而,當我通過PyCharm中的模塊進行搜索時,最接近出現的是來自Zope Foundation的「DateTime」。
當我嘗試按以下方式插入數據時,收到錯誤「ProgrammingError:syntax error at or near」日期」。
cur.execute("INSERT INTO invigilation (course_id date room_id duration)
\VALUES (%s, %s, %s, %s", (course_id, date, room_id, str(duration)))