[0.6.0] can't use sa.func.text(...)

Issue #1798 resolved
Former user created an issue

I have a non-TEXT column I would like converted to TEXT. In PostgreSQL I would normally do either this:

SELECT foo::text from table;

or

SELECT text(foo) from table;

When I tried to do this with the 'func' functionality, I get an error:

    column = sa.func.text(table.c[key](key))
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/sql/expression.py", line 859, in __call__
    return func(*c, **o)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/sql/expression.py", line 820, in text
    return _TextClause(text, bind=bind, *args, **kwargs)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/sql/expression.py", line 2348, in __init__
    self.text = self._bind_params_regex.sub(repl, text)
TypeError: expected string or buffer
----------------------------------------

However, as a test, I tried sa.func.date and others, and they all work. Am I crazy thinking that this should work?

Comments (3)

  1. Mike Bayer repo owner
    • changed component to sql
    • assigned issue to
    • changed milestone to 0.6.1

    this is a bug. here's a patch that will be committed soon:

    diff -r 25e7dc60dfa739692421a9576c83f2db29f73cb2 lib/sqlalchemy/sql/expression.py
    --- a/lib/sqlalchemy/sql/expression.py  Mon May 10 11:37:48 2010 -0400
    +++ b/lib/sqlalchemy/sql/expression.py  Tue May 11 13:15:22 2010 -0400
    @@ -855,7 +855,7 @@
                 if functions is None:
                     from sqlalchemy.sql import functions
                 func = getattr(functions, self.__names[-1](-1).lower(), None)
    -            if func is not None:
    +            if func is not None and func.__module__ == functions.__name__:
                     return func(*c, **o)
    
             return Function(
    
  2. Log in to comment