Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python mysql更新时间戳_Python_Mysql_Timestamp - Fatal编程技术网

python mysql更新时间戳

python mysql更新时间戳,python,mysql,timestamp,Python,Mysql,Timestamp,嗨,我需要帮助了解如何只更新独立于任何列的timestamp列。我一直在谷歌上搜索这个例子,但我没有看到任何相关的例子。下面我粘贴了代码,用于测试ID=1,但没有更新ID=1的时间。不过,我的目标是更新所有行的时间戳,而不考虑列名 *TLATemplate已包含名为“timestamp”的列 *config是一个已导入时间的模块 谢谢大家! 下面是我的代码: sql = "CREATE TABLE %s like TLAKnoxT5Template" %TLA_dict['TLA_name']

嗨,我需要帮助了解如何只更新独立于任何列的timestamp列。我一直在谷歌上搜索这个例子,但我没有看到任何相关的例子。下面我粘贴了代码,用于测试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)

不使用
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())))

@用户3761743,看起来您的时间戳没有被引用,请参阅更新的回答谢谢!你能解释一下'%s'是什么意思吗?单引号的意义是什么?在python中,
%s
是字符串插值中使用的占位符,如
'hello%s'('world',)
。时间戳周围需要单引号,因为mysql要求非数值用引号括起来,如
t='2014-01-01 00:00:00'