converting SQL window function to SqlAlchemy

Viewed 7

I'm new with SqlAlchemy window functions.

I have SQL statement which works fine and i try to convert it to SqlAlchemy code

How it can be done? Thank in advance.

select p.id,
       p.submitted_at,
       p.user_id,
       first_value(p.submitted_at) over (partition by "user_id" order by p.submitted_at DESC) as last_project

from project p join "user"  u on p."user_id" = u.id

  

I start with this one but receive AttributeError Neither Over object Comparator has attribute all:

 with get_session() as session:
        query = session.query(Project, User)
        query = query.join(User, User.id == Project.user_id)
        query = func.first_value(Project.submitted_at).over(
            partition_by= "user_id", order_by=Project.submitted_at
        )
       query.all() # AttributeError
0 Answers
Related