A
A
Alexander2015-02-25 11:34:42
Python
Alexander, 2015-02-25 11:34:42

How to get the last row in a column using sqlalchemy?

Good afternoon, I am learning to work with the postgresql database and using sqlalchemy, I have a table in it with 1 column, I display all the value from it in such a cycle -

for instance in db_session.query(Courses).order_by(Courses.courses_now):
    print(instance.courses_now)

it outputs to me:
56.2345
63.5083
65.0862
So the question is: how to get constantly and display the last value from this column?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xSkyFoXx, 2015-02-25
@xSkyFoXx

db_session.query(Courses).order_by(Courses.courses_now)[-1]

or (more kosher)
db_session.query(Courses).order_by(Courses.courses_now.id.desc()).first()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question