When using convert_unicode=True, regular select returns unicode, but select distinct does not.

Issue #1420 resolved
Former user created an issue

When using convert_unicode=True, regular select returns unicode, but select distinct does not.

# Normal select returns unicode
sql.select([t.c.text](t.c.text))

# Select distinct does not return unicode
sql.select([t.c.text.distinct()](t.c.text.distinct()))

See attached code. Only tested with postgres. Probably not a problem on sqlite if pysqlite converts all strings to unicode.

Comments (5)

  1. Mike Bayer repo owner
    • changed component to sql
    • changed milestone to 0.5.xx

    heres a possible patch:

    Index: lib/sqlalchemy/sql/expression.py
    ===================================================================
    --- lib/sqlalchemy/sql/expression.py    (revision 5974)
    +++ lib/sqlalchemy/sql/expression.py    (working copy)
    @@ -400,9 +400,9 @@
    
     def distinct(expr):
         """Return a ``DISTINCT`` clause."""
    +    expr = _literal_as_binds(expr)
    +    return _UnaryExpression(expr, operator=operators.distinct_op, type_=expr.type)
    
    -    return _UnaryExpression(expr, operator=operators.distinct_op)
    -
     def between(ctest, cleft, cright):
         """Return a ``BETWEEN`` predicate clause.
    
    @@ -1477,7 +1477,7 @@
         def distinct(self):
             """Produce a DISTINCT clause, i.e. ``DISTINCT <columnname>``"""
    
    -        return _UnaryExpression(self, operator=operators.distinct_op)
    +        return _UnaryExpression(self, operator=operators.distinct_op, type_=self.type)
    
         def between(self, cleft, cright):
             """Produce a BETWEEN clause, i.e. ``<column> BETWEEN <cleft> AND <cright>``"""
    
  2. Log in to comment