Skip to content

Commit badf827

Browse files
committed
Support for Postgres's MIN(..) and MAX(..) functions
1 parent cb258ce commit badf827

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

psqlextra/expressions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,28 @@ def resolve_expression(self, *args, **kwargs) -> HStoreColumn:
8686
self.key
8787
)
8888
return expression
89+
90+
class NonGroupableFunc(expressions.Func):
91+
"""A version of Django's :see:Func expression that
92+
is _never_ included in the GROUP BY clause."""
93+
94+
def get_group_by_cols(self):
95+
"""Gets the columns to be included in the GROUP BY clause.
96+
97+
We have to override this because Django's default behavior
98+
is to include function calls in GROUP by clauses."""
99+
return []
100+
101+
102+
class Min(NonGroupableFunc):
103+
"""Exposes PostgreSQL's MIN(..) func."""
104+
105+
def __init__(self, expression):
106+
super().__init__(expression, function='MIN')
107+
108+
109+
class Max(NonGroupableFunc):
110+
"""Exposes PostgreSQL's Max(..) func."""
111+
112+
def __init__(self, expression):
113+
super().__init__(expression, function='Max')

0 commit comments

Comments
 (0)