繁体   English   中英

如何调试cursor.execute(psycopg2)为NoneType

[英]How to debug cursor.execute (psycopg2) is NoneType

我尝试对我的postgres数据库运行SQL,

我通过的连接对象

import psycopg2
conn_string = "host='localhost' port='5432' dbname='postgres' user='postgres' password='mysecretpassword'"
conn = psycopg2.connect(conn_string)

似乎还可以

result = cursor.execute(
"""
select 
* 
from 
planet_osm_point limit 10
""")

结果是Nonetype,所以一定有问题吗?

我做错了什么? 我该如何调试呢?

cursor.execute()仅执行查询,不获取任何数据。 为了接收数据,您将需要调用cursor.fetchall()cursor.fetchone()

import psycopg2
conn_string = "host = 'localhost' port = '5432' dbname = 'postgres' user = 'postgres' password = 'mysecretpassword'"
conn = psycopg2.connect(conn_string)
cursor.execute(
""" 
select 
* 
from 
planet_osm_point limit 10
""")

result = cursor.fetchall()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM