简体   繁体   中英

In Python 3, using mysql.connector, passing mysql function in insert

I am using Python 3.4 and mysql.connector. I would like to to enter something like this in an insert statement:

st = 'insert into tbl(rate,inputDt) values(%s,%s)'
data = (rate, NOW())
cur.execute(st,data)

Where NOW() is the mysql function for current datetime

I can get the equivalent value by constructing a variable in Python:

today = date.today()

But how can I pass the the mysql function as above?

Not familiar with this, but I think you can pass the MySQL function as a string.

st = 'insert into tbl(rate,inputDt) values(%s,NOW())'
data = (rate)
cur.execute(st,data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM