PEP-249为数据库驱动程序指定API,^{}也遵循此APIpg8000 is a DB-API 2.0 compatible pure-Python interface to the PostgreSQL database engine.Parameters may be provided as sequence or mapping and will be bound to variables in the operation.
我们可以在^{} sources上看到一个如何将参数传递给查询的示例。在
所以您应该传递一个tuple/list的值,而不是值本身。在
另外,我们应该首先执行查询,然后使用^{}或{a6}或{a7}获取其结果,因为execute本身返回{a8}(更多信息请参见sources)。我想OP需要一个记录,所以我们将使用fetchone。在
注意:fetchone方法返回表示为tuple的记录,因此如果我们需要第一个坐标,那么我们应该get it using zero index。在
在您的情况下,您应该尝试:parameters = (str(member_id),) # WARNING: don't miss the comma
cursor.execute("SELECT titlequery(%s)", parameters)
title = cursor.fetchone()[0]
或者
^{pr2}$
示例
这对我有用import pg8000
table_definition = """
CREATE TABLE Member(
title VARCHAR(40) NOT NULL,