5

Ran into a problem and something that seemed simple at first.

I want to do this (query has been dumbed down for brevity here, it's actually much longer and more complex):

    query  = ("""INSERT INTO %s " % cfg['mysql.table']
              "('hostname', 'timestamp', 'metric', 'average', 'peakhigh', 'peaklow', 'gsamp', 'zsamp', 'nsamp')"""
              "VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s )"
             )   

So how do I incorpoarate STR_TO_DATE into this query for the timestamp field?

Thanks for any help.

2
  • Try building your query inside triple quotes. Commented May 27, 2016 at 15:53
  • How do you do this component of the string using the triple quote approach though - "INSERT INTO %s " % cfg['mysql.table']? Commented May 27, 2016 at 15:54

1 Answer 1

7

Put your string inside triple quotes:

query  = ("""INSERT INTO %s " % cfg['mysql.table']
              "('hostname', 'timestamp', 'metric', 'average', 'peakhigh', 'peaklow', 'gsamp', 'zsamp', 'nsamp')"
              "VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s )"""
             ) 
Sign up to request clarification or add additional context in comments.

3 Comments

Ok let me try that again, I must have fat-fingered something when I tried this approach before posting.
Any idea how I incoproate STR_TO_DATE for the timestamp field?
Try changing the second %s with STR_TO_DATE(%s, '%d/%m/%Y') if that matches the dd/mm/YYYY format you require.

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.