gpt4 book ai didi

python - 为什么我无法在Python中获取sql语句?

转载 作者:行者123 更新时间:2023-11-29 06:20:48 25 4
gpt4 key购买 nike

我有一个非常大的表(374870 行),当我运行以下代码时,时间戳最终会成为一个值为 374870 的 long int......我希望能够获取表中的所有时间戳。 ..但我得到的只是一个 long int :S

import MySQLdb

db = MySQLdb.connect(
host = "Some Host",
user = "SOME USER",
passwd = "SOME PASS",
db = "SOME DB",
port = 3306

)

sql = "SELECT `timestamp` from `table`"

timestamps = db.cursor().execute(sql)

最佳答案

试试这个:

cur = db.cursor()
cur.execute(sql)
timestamps = []
for rec in cur:
timestamps.append(rec[0])

关于python - 为什么我无法在Python中获取sql语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3778935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com