Created
May 5, 2018 16:14
-
-
Save rdmurphy/3f73c7b1826cacee34f6c2a855b12e2e to your computer and use it in GitHub Desktop.
PostgreSQL specific Django Median aggregation function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Aggregate, FloatField | |
class Median(Aggregate): | |
function = 'PERCENTILE_CONT' | |
name = 'median' | |
output_field = FloatField() | |
template = '%(function)s(0.5) WITHIN GROUP (ORDER BY %(expressions)s)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment