Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building multi-line database queries in python

Tags:

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.

like image 345
BenH Avatar asked May 27 '16 15:05

BenH


1 Answers

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 )"""
             ) 
like image 65
Gadget Avatar answered Oct 03 '22 14:10

Gadget