How to use the method tablesample #1501
Answered
by
YuriiMotov
santigandolfo
asked this question in
Questions
-
First Check
Commit to Help
Example Codefrom sqlalchemy import func
selectable = people.tablesample(
func.bernoulli(1),
name='alias',
seed=func.random())
stmt = select(selectable.c.people_id) DescriptionI'm trying to use the tablesample method defined in SQLAlchemy, but I can't seem to understand how to migrate it's structure from the sample code into SQLModel code. Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.4 Python Version3.9.7 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Aug 12, 2025
Replies: 1 comment
-
For further readers: from typing import Optional
from sqlalchemy import func, tablesample
from sqlmodel import Field, SQLModel, select
class People(SQLModel, table=True):
people_id: Optional[int] = Field(default=None, primary_key=True)
name: str
selectable = tablesample(People, func.bernoulli(1), name="alias", seed=func.random())
stmt = select(selectable.c.people_id)
print(stmt) Output:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For further readers:
Output: