build generic functions for max, min

Issue #1160 resolved
Former user created an issue

result of a ''select ... max(col)'' where col is a DateTime or Numeric (or may be others) does not return this type but a "simple" scalar type like unicode, int, float...

It may be specific to SQLite.

Comments (6)

  1. Mike Bayer repo owner

    if anyone is interested in volunteering for this, the functions would be added to lib/sqlalchemy/sql/functions.py, unit tests in test/sql/functions.py .

    FYI the current non-generic methodology is:

    func.max(somecol, type_=DateTime)
    

    hence not a bug.

  2. Former user Account Deleted

    I've just attached a patch and test. I hope it will be ok (my first patch for SA...)

    Remi.

  3. Mike Bayer repo owner
    • changed milestone to 0.5.0

    It looks pretty good. there's a lot of other functions that fall under this category, like "avg()", etc. but we can start with that one. will try to get it for 0.5.0.

  4. Former user Account Deleted

    Before sending the patch, I had tried to add avg also but when I tested it against a sqlite db, it raised an error (AttributeError) when trying to do A.query.avg(DateTimeColumn)...

    I think that all functions that return a scalar value should fall under the same category. I've just tested sum(). Of course sum(Date) is nonsense but sum(Decimal) should return a Decimal...

  5. Log in to comment