python mysql更新时间戳

2024-04-20 11:18:54 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我需要帮助了解如何更新独立于任何列的时间戳列。我一直在谷歌上搜索这个例子,但我没有看到任何相关的例子。下面我粘贴了ID=1用于测试的代码,但是ID=1的时间没有更新。不过,我的目标是更新所有行的时间戳,而不管列名是什么。在

*TLATemplate已包含名为“timestamp”的列 *config是一个导入了时间的模块

谢谢你!在

以下是我的代码:

sql = "CREATE TABLE %s like TLAKnoxT5Template" %TLA_dict['TLA_name']
config.cursor.execute(sql)
config.db.commit()
#copy entire table
sql = "INSERT INTO %s SELECT * FROM TLAKnoxT5Template"%TLA_dict['TLA_name']
config.cursor.execute(sql)
config.db.commit()

#update timestamp
sql = "UPDATE %s SET TIMESTAMP = %s WHERE ID = 1"%   
(TLA_dict['TLA_name'],config.time.strftime("%Y-%m-%d %H:%M:%S",/
config.time.localtime(config.time.time())))
config.cursor.execute(sql)

Tags: 代码nameidconfigexecutedbsqltime
1条回答
网友
1楼 · 发布于 2024-04-20 11:18:54

不使用WHERE语句,并引用时间戳

sql = "UPDATE %s SET TIMESTAMP = '%s'" % (TLA_dict['TLA_name'], config.time.strftime("%Y-%m-%d %H:%M:%S", config.time.localtime(config.time.time())))

相关问题 更多 >