开发者社区> 问答> 正文

python从postgressql中的列中取值,但是总是报错

报错信息:

Type Error Boolean value of this clause is not define 

以下是我的代码:

import psycopg2
from sqlalchemy import text

connection = psycopg2.connect(user="postgres",
                              password="admin",
                              host="localhost",
                              port="5432",
                              database="myDB")

db = connection.cursor()
query = text("""
     SELECT input, input_type, value, output
     FROM value_rules
 """)
result = db.execute(query).fetchone()
print(result)

我理解只是一个简单的查询,不知道为什么会报错

展开
收起
安忆333 2019-12-03 17:34:05 882 0
1 条回答
写回答
取消 提交回答
  • db.execute
    

    不能去处理.TextClause 类型的对象,

    将.execute()的参数从文本对象更改为普通字符串

    ...
    query = """
         SELECT input, input_type, value, output
         FROM value_rules
     """
     ...
    
    2019-12-03 17:39:17
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载