我有以下Python MySQL查询:
sql = "INSERT INTO Tweets(timestamp, message_id, body, username, symbol_id, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE timestamp=VALUES(timestamp), message_id=VALUES(message_id), body=VALUES(body), username=VALUES(username), symbol_id=VALUES(symbol_id), created_at=NOW(), updated_at=NOW()"% \
(timestamp, messageId, body, username, dbID, currentTime, currentTime)
一切正常,直到我点击ON DUPLOCATE KEY UPDATE
updated_at
被NOW()
时间戳替换。我尝试删除currentTime
和updated_at=NOW()
,但会收到以下错误:
Traceback (most recent call last):
File "./parseTweets.py", line 50, in <module>
(timestamp, messageId, body, username, dbID, currentTime)
TypeError: not enough arguments for format string
我不希望updated_at
替换为created_at
,如果它只是更新行