-
-
Save illia-v/b5af28cceabc4c64816b5b87cca03e49 to your computer and use it in GitHub Desktop.
How to limit results of a database query per group using SQLAlchemy and PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from faker import Faker | |
fake = Faker() | |
for _ in range(3): | |
query = authors_table.insert().values(name=fake.name()) | |
engine.execute(query) | |
result = engine.execute(authors_table.select()) | |
for author_id in (author.id for author in result): | |
for _ in range(5): | |
query = articles_table.insert().values( | |
author_id=author_id, | |
title=fake.text(15)[:-1], | |
text=fake.text(20) + '..', | |
views=fake.pyint(), | |
) | |
engine.execute(query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment