From b403f156fedf7f1c3da34818f5ebe9debab481d7 Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Thu, 24 Jul 2008 21:36:16 +0000 Subject: - func.count() with no argument emits COUNT(*) --- lib/sqlalchemy/sql/functions.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/functions.py') diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 7303bd0c6..7fce3b95b 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -1,6 +1,6 @@ from sqlalchemy import types as sqltypes from sqlalchemy.sql.expression import ( - ClauseList, _FigureVisitName, _Function, _literal_as_binds, + ClauseList, _FigureVisitName, _Function, _literal_as_binds, text ) from sqlalchemy.sql import operators @@ -61,6 +61,16 @@ class random(GenericFunction): kwargs.setdefault('type_', None) GenericFunction.__init__(self, args=args, **kwargs) +class count(GenericFunction): + """The ANSI COUNT aggregate function. With no arguments, emits COUNT *.""" + + __return_type__ = sqltypes.Integer + + def __init__(self, expression=None, **kwargs): + if expression is None: + expression = text('*') + GenericFunction.__init__(self, args=(expression,), **kwargs) + class current_date(AnsiFunction): __return_type__ = sqltypes.Date -- cgit v1.2.1