python - Postgre 和pyodbc 的 bool 值不兼容?

标签 python postgresql pyodbc

我正在使用 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/

相关文章:

python - 每次调用函数时都会从 'origin-module' 中抓取一个函数吗?

python - Pandas:如何加载包含多个 txt 文件的 zip 文件?

python - 解析文本以替换引号和嵌套引号

PostgreSQL 将数据从递归 CTE 传递到函数

sql - pyodbc 执行命令不接受?参数正确?

python - tkinter GUI 按钮列表

sql - postgreSQL中的@@Fetch_status

python - 使用 connection.execute() 的 sqlalchemy 原始 sql 查询限制

python - 将 SQL Server 表缓慢加载到 pandas DataFrame 中

python - 加快从 pyodbc 插入 SQL Server