如何解决Python 3 Postgresql psycopg2 fetchall,fetchmany,fetchone方法在查询结果给出行时全部为空
我想从表中获取所有数据。尽管表中有数据fetchall(),fetchmany(),fetchone()方法都没有。 (我在注释中打印了打印结果。)rowcount和len也得到1。我不使用任何想法。 这有什么问题?我看到了类似的问题,但没有确定的答案。例如:Python psycopg2 cursor.fetchall() returns empty list but cursor.rowcount is > 1
conn = psycopg2.connect(...)
cursor = conn.cursor()
cursor.execute("""SELECT * FROM sw_user_info""")
len_cur = len(cursor.fetchall())
print(len_cur) # 1
print(len(cursor.fetchall())) #0
crsr_rw = cursor.rowcount
print(crsr_rw) #1
print(cursor.fetchone()) #None
totalS = cursorSize.fetchone()[0]
print(totalS) #1
print(cursor.fetchmany(1)) #[]
try:
if not cursor.fetchall():
print("--1--List is empty") #print
else:
print("--1--List is not empty")
if not len(cursor.fetchall()):
print("--2--List is empty") #print
else:
print("--2--List is not empty")
if len(cursor.fetchall()) == 0:
print("--3--List is empty") #print
else:
print("--3--List is not empty")
if cursor.fetchall() == []:
print("--4--List is empty") #print
else:
print("--4--List is not empty")
except Exception as exception:
print(exception)
finally:
cursor.close()
conn.close()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。