So I want to specifically run this sql code in my flask app:
SELECT *, (upvotes - downvotes) * age / importance * -1 AS hotness FROM 'post' ORDER BY hotness DESC LIMIT 50
To do this I used flask-sqlalchemy like so:
self.hotness = db.engine.execute(text("SELECT *, (upvotes - downvotes) * age / importance * -1 AS hotness FROM 'post' ORDER BY hotness DESC LIMIT 50").execution_options(autocommit=True))
return self.hotness
As suggested on this question.
The problem is that the self.hotness
variable always comes out as None
even though all the other variables referenced in the sql code are not None
, they are numbers.
I'm guessing that the problem is due to the actual sql code not being committed into the table used here, which is post
.
How would I properly commit data made from raw sql using flask-sqlalchemy?