import string, re, random, sets
types = __import__('types')
-__all__ = ['text', 'table', 'column', 'func', 'select', 'update', 'insert', 'delete', 'join', 'and_', 'or_', 'not_', 'between_', 'case', 'cast', 'union', 'union_all', 'null', 'desc', 'asc', 'outerjoin', 'alias', 'subquery', 'literal', 'bindparam', 'exists']
+__all__ = ['text', 'table', 'column', 'func', 'select', 'update', 'insert', 'delete', 'join', 'and_', 'or_', 'not_', 'between_', 'case', 'cast', 'union', 'union_all', 'null', 'desc', 'asc', 'outerjoin', 'alias', 'subquery', 'literal', 'bindparam', 'exists', 'extract']
def desc(column):
"""returns a descending ORDER BY clause element, e.g.:
"""
return Cast(clause, totype, **kwargs)
-
+def extract(field, expr):
+ """return extract(field FROM expr)"""
+ expr = BinaryClause(text(field), expr, "FROM")
+ return func.extract(expr)
+
def exists(*args, **params):
params['correlate'] = True
s = select(*args, **params)
# test a dotted func off the engine itself
self.runtest(func.lala.hoho(7), "lala.hoho(:hoho)")
+
+ def testextract(self):
+ """test the EXTRACT function"""
+ self.runtest(select([extract("month", table3.c.otherstuff)]), "SELECT extract(month FROM thirdtable.otherstuff) FROM thirdtable")
+
+ self.runtest(select([extract("day", func.to_date("03/20/2005", "MM/DD/YYYY"))]), "SELECT extract(day FROM to_date(:to_date, :to_da_1))")
def testjoin(self):
self.runtest(