From 85d335b01bf64a27e99cee915205afd99e7191b5 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 11 Feb 2010 19:33:06 +0000 Subject: - The type/expression system now does a more complete job of determining the return type from an expression as well as the adaptation of the Python operator into a SQL operator, based on the full left/right/operator of the given expression. In particular the date/time/interval system created for Postgresql EXTRACT in [ticket:1647] has now been generalized into the type system. The previous behavior which often occured of an expression "column + literal" forcing the type of "literal" to be the same as that of "column" will now usually not occur - the type of "literal" is first derived from the Python type of the literal, assuming standard native Python types + date types, before falling back to that of the known type on the other side of the expression. Also part of [ticket:1683]. --- lib/sqlalchemy/dialects/postgresql/base.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index cfbef69e8..7d4cbbbd8 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -349,9 +349,16 @@ class PGCompiler(compiler.SQLCompiler): def visit_extract(self, extract, **kwargs): field = self.extract_map.get(extract.field, extract.field) - affinity = sql_util.determine_date_affinity(extract.expr) - - casts = {sqltypes.Date:'date', sqltypes.DateTime:'timestamp', sqltypes.Interval:'interval', sqltypes.Time:'time'} + if extract.expr.type: + affinity = extract.expr.type._type_affinity + else: + affinity = None + + casts = { + sqltypes.Date:'date', + sqltypes.DateTime:'timestamp', + sqltypes.Interval:'interval', sqltypes.Time:'time' + } cast = casts.get(affinity, None) if isinstance(extract.expr, sql.ColumnElement) and cast is not None: expr = extract.expr.op('::')(sql.literal_column(cast)) -- cgit v1.2.1