Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the OVER window function in SQLAlchemy

How would I get the total count of a limited result with SQLAlchemy. I am currently using Postgres so I know I can use windowed functions. I basically want to know how I would write the following in SQLAlchemy:

SELECT foo
  ,count(*) OVER() AS full_count
FROM   bar
ORDER  BY <some col>
LIMIT  <pagesize>
OFFSET <offset>
like image 538
Vincent Catalano Avatar asked Oct 22 '22 18:10

Vincent Catalano


1 Answers

Something like:

select(
    [
        bar.c.foo,
        func.count().over().label('full_count'),
    ],
    ...
)

Ticket where this was introduced: http://www.sqlalchemy.org/trac/ticket/1844#comment:9

like image 62
sayap Avatar answered Oct 28 '22 20:10

sayap