简体   繁体   中英

How to call a postgresql sql function in sqlalchemy in an update query

I am new to sqlalachemy in python and i have a question. I need to port this query:

UPDATE user_list SET last_visit=now()  WHERE   name='"+username+"'

I have read a lot about the update query, but I see possibility to set the value of the last_visit to the value generated by the now() function of postgresql. How would I do that properly? Assume that I would use the update functions of sqlalachemty. I could generate this as sql string and execute() it, but then the statement could be subject of sql injection. How to do this right?

You can use func.now() (import func from sqlalchemy ).

Reference: http://docs.sqlalchemy.org/en/latest/core/functions.html

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