본문 바로가기

Python

[SQLAlchemy] 윈도우 함수 orm으로 사용

반응형

https://docs.sqlalchemy.org/en/20/tutorial/data_select.html#using-window-functions

 

Using SELECT Statements — SQLAlchemy 2.0 Documentation

 

docs.sqlalchemy.org

stmt = (
    select(
        func.row_number().over(partition_by=user_table.c.name),
        user_table.c.name,
        address_table.c.email_address,
    )
    .select_from(user_table)
    .join(address_table)
)
with engine.connect() as conn:  
    result = conn.execute(stmt)
    print(result.all())
반응형