Skip to content

How to use the method tablesample #1501

Discussion options

You must be logged in to vote

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:

SELECT alias.people_id 
FROM people AS alias TABLESAMPLE bernoulli(:bernoulli_1) REPEATABLE (random())

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #172 on August 12, 2025 19:32.