From 58c5bb7fc104da26cd1797d9680a810a3b79ab0a Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 8 Sep 2008 03:51:47 +0000 Subject: - Added func.min(), func.max(), func.sum() as "generic functions", which basically allows for their return type to be determined automatically. Helps with dates on SQLite, decimal types, others. [ticket:1160] - added decimal.Decimal as an "auto-detect" type; bind parameters and generic functions will set their type to Numeric when a Decimal is used. --- lib/sqlalchemy/sql/functions.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql/functions.py') diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 7fce3b95b..c7a0f142d 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -36,12 +36,25 @@ class AnsiFunction(GenericFunction): def __init__(self, **kwargs): GenericFunction.__init__(self, **kwargs) - -class coalesce(GenericFunction): +class ReturnTypeFromArgs(GenericFunction): + """Define a function whose return type is the same as its arguments.""" + def __init__(self, *args, **kwargs): kwargs.setdefault('type_', _type_from_args(args)) GenericFunction.__init__(self, args=args, **kwargs) +class coalesce(ReturnTypeFromArgs): + pass + +class max(ReturnTypeFromArgs): + pass + +class min(ReturnTypeFromArgs): + pass + +class sum(ReturnTypeFromArgs): + pass + class now(GenericFunction): __return_type__ = sqltypes.DateTime -- cgit v1.2.1