0

Hi I need help understanding how to update just the timestamp column independent of any column. I've been searching on google for an example of this but I don't see any relevant examples. Below I've pasted code that does it for ID = 1 for testing purposes but there was no update to the time for ID = 1. My goal though is to update the timestamp for all rows regardless of the column name.

*TLATemplate already contains column called 'timestamp' *config is a module that has imported time

Thank you!

Below is my code:

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)
0

1 Answer 1

1

do it without the WHERE statement, and quote the timestamp

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())))
Sign up to request clarification or add additional context in comments.

3 Comments

@user3761743, looks like your timestamp was not quoted, see updated answer
thank you! Could you please explain what the '%s' means? What is the significance of the single quotes?
In python, %s is the placeholder used in string interpolation like 'hello %s' % ('world',). The single quote is needed around the timestamp because mysql require non-numeric values to be surrounded with quotes like t = '2014-01-01 00:00:00'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.