python mysql 更新时间戳
你好,我需要帮助理解如何独立更新时间戳这一列,而不影响其他任何列。我在谷歌上搜索了相关的例子,但没有找到合适的。下面我粘贴了一个代码,这个代码是为了测试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)
1 个回答
1
不使用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())))