Mandragor
Mandragor

Reputation: 5544

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?

Upvotes: 0

Views: 2184

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318468

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

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

Upvotes: 1

Related Questions