On Jun 30, 2011, at 9:23 AM, Adrian wrote:

> SQAlchemy 0.7.1 / pyscopg 2.2.1 / PostgreSQL 9.0
> ---------------------------------------------------------------------------
> 
> I have a weird problem with orm queries that contain custom functions,
> in this case from postgres contrib modules. When I do a query like
> this
> 
> session.query(Entity, func.similarity(Entity.string,
> 'querystring')).all() # postgres pg_trgm extension
> 
> I will get the error below. However, when I specify one or all the
> columns of the Entity individually it works. It also works if the
> function is in the .order_by() clause.
> 
> Any ideas where the problem could come from?

this seems like it has to do with the type of object being returned from 
psycopg2, as the Query runs the rows through a uniquing function that uses 
sets, maybe a comparison is emitting that TypeError.   The stack trace doesn't 
quite make it clear.   It would be interesting to see what 
session.execute(myquery.statement) sends back in the result rows.   (I haven't 
looked up the "SIMILARITY" function in the PG docs yet to see what it returns).



> 
> -----
> 
> /usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.pyc in
> all(self)
>   1675
>   1676         """
> -> 1677         return list(self)
>   1678
>   1679     @_generative(_no_clauseelement_condition)
> 
> /usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/query.pyc in
> instances(self, cursor, _Query__context)
>   1916
>   1917             if filter:
> -> 1918                 rows = filter(rows)
>   1919
>   1920             if context.refresh_state and self._only_load_props
> \
> 
> /usr/local/lib/python2.7/dist-packages/sqlalchemy/util/
> _collections.pyc in unique_list(seq, hashfunc)
>    594     if not hashfunc:
>    595        return [x for x in seq
> --> 596                 if x not in seen
>    597                 and not seen.__setitem__(x, True)]
>    598     else:
> 
> TypeError: an integer is required
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to