Invalid SQL emitted for over(partition_by=[]) and over(order_by=[])

Issue #2574 resolved
Former user created an issue

For queries like this:

select([func.sum(tab.c.id).over(partition_by=[](func.sum(tab.c.id).over(partition_by=[))])

invalid SQL is emitted:

SELECT sum(foo.id) OVER (PARTITION BY ) AS anon_1 
FROM foo

Passing empty lists has a reasonably well defined meaning (don't partition/order by anything), and may arise as a consequence of code like partition_by=list(determine_partition_expressions()), where restructuring the code to not pass the parameter if its value will be empty is an unnecessary inconvenience.

Submitting a patch with tests.

Comments (11)

  1. Former user Account Deleted

    Oh, patch also includes test for over() with no parameters — that was already working, but no harm having a test for it.

  2. Mike Bayer repo owner
    • changed milestone to 0.7.9

    can this patch be done more simply by just asking for "if clause.order_by is not None and len(clause.order_by)" ? would be more succinct.

  3. Former user Account Deleted

    Sure. Attaching two alternative implementations, one that changes things minimally the way you describe, and another that eliminates redundancy but reads more functionally. Both pass the tests.

  4. Log in to comment