T
T
toddbarry2019-01-10 16:48:03
Python
toddbarry, 2019-01-10 16:48:03

How to get from the database all rows in Gino whose id matches one of the values ​​in the list using async for?

I need to get from the database all the lines whose id matches one of the values ​​in the initially given list. The list can be quite large, so sending queries sequentially to the database is a bad option. For this reason, I need to use

async for Table.select('ids').where(Table.id in spisok).gino.iterate():

However, the where method does not understand this syntax, and the official manual did not find a way to implement this.
Another way - triggering sending requests via asyncio.as_completed() results in an asyncpg error:
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress

In general, I need to get from the table all the values ​​of the ids column in those rows in which the id matches one of the values ​​of the spisok list, then form a new list from the obtained ids values ​​and repeat the operation for it.
If somehow it was possible to ask the database to do such iterations with one request, this would be the best way out in my situation, but I can’t find such examples.
Please help me with this task

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
toddbarry, 2019-01-10
@toddbarry

Found the method Table.id.in_(spisok)
Everything works well. So the question now boils down to just this

In general, I need to get from the table all the values ​​of the ids column in those rows in which the id matches one of the values ​​of the spisok list, then form a new list from the obtained ids values ​​and repeat the operation for it.
If somehow it was possible to ask the database to do such iterations with one request, this would be the best way out in my situation, but I can’t find such examples.

And ask for evaluation using Table.id.in_(spisok) - is this a good approach?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question