如何调试 cursor.execute (psycopg2) is NoneType
How to debug cursor.execute (psycopg2) is NoneType
我尝试 运行 SQL 针对我的 postgres 数据库,
我通过的连接对象
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()
我尝试 运行 SQL 针对我的 postgres 数据库,
我通过的连接对象
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()