我正在使用 pyodbc 3.0.10 和 PostgreSQL 9.6,使用 native Postgre odbc 驱动程序 (Postgre Unicode (x64))。我创建了一个测试表
create table test ( col boolean )
然后我尝试插入一个 Python bool 值。我看不到进行了哪些参数替换,但似乎 pyodbc 不适用于所有 Postgre 数据类型?
In [3]: cur = cxn.cursor()
In [4]: cur.execute('insert into test values (?)', (True,))
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
<ipython-input-4-5a0edc50457d> in <module>()
----> 1 cur.execute('insert into test values (?)', (True,))
ProgrammingError: ('42804', '[42804] ERROR: column "col" is of type boolean but
expression is of type "char";\nError while preparing parameters (1) (SQLExecDirectW)')
最佳答案
正如 Gord Thompson 在上面指出的那样,您所要做的就是将 ;BoolsAsChar=0
添加到连接字符串中
关于python - Postgre 和pyodbc 的 bool 值不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41331235/