K
K
Kirill2019-11-19 11:46:51
Flask
Kirill, 2019-11-19 11:46:51

How to submit a deletion request?

Hello!

Guys, I'm stupid, I've been sitting for several hours, I can't drink everything, how can I delete all the records that fall under the range?

There is a jobs table in this table there is an add_date column (type INT) I store the date in UNIX, I want to filter on this column and delete all records that are more than 30 days old.

I make a request like this:

Jobs.query.filter(Jobs.add_date < (int(time.time()) - 60 * 60 * 24 * 30)).delete(synchronize_session=False)


But alas, the request does not work. I can’t catch up with how to make a where condition in SQLAlchemy, I worked with regular SQL, but I can’t make friends with SQLAlchemy, although I already read the documentary like Yesenin’s poems)

I would be grateful for the hint.

PS The problem turned out to be just inattention, I threw the correct code here, and instead of the less than sign, the greater than sign in the comparison expression was used.
Well, maybe someone will come in handy, here is the working code:
Jobs.query.filter(Jobs.add_date < (int(time.time()) - 60 * 60 * 24 * 30)).delete()
db.session.commit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
glader, 2019-11-19
@Lobanov

Maybe this will help you https://stackoverflow.com/questions/8895208/sqlalc...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question