coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.06k stars 1.37k forks source link

support for fn.PERCENTILE_CONT #2887

Closed saknius closed 4 months ago

saknius commented 4 months ago

i wanted to execute this in peewee SELECT PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY x) FROM t; by any chance is fn.PERCENTILE_CONT supported in peewee or if there is any workaround please suggest.

coleifer commented 4 months ago

You can write a wrapper:

from peewee import *
from peewee import NodeList

def percentile_cont(amt, order_by):
    return NodeList((
        fn.PERCENTILE_CONT(amt),
        SQL('WITHIN GROUP(ORDER BY '),
        order_by,
        SQL(')'),
    ))

Table.select(percentile_cont(0.5, Table.x))