print Session().query(
        mytable.c.col1, 
            mytable.c.col2, 
            mytable.c.col3).\
            distinct().\
        filter(mytable.c.col1=='something').\
        limit(1).offset(2).\
        from_self(func.count('*'))

or just say count() instead of from_self(), will execute it.   you don't need 
"distinct(col1, col2, col3)" here, only "DISTINCT col1, col2, col3", since you 
aren't applying DISTINCT to a subset of the available columns.  DISTINCT(x, y, 
z) is a Postgresql-specific extension (see 
http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-DISTINCT )




On May 16, 2012, at 1:50 PM, Eduardo wrote:

> SORRY
> 
> I want to create query that will return as a first element the number of hits 
> 
> SELECT COUNT(*) FROM(SELECT (DISTINCT(col1,col2,col3)) FROM mytable where 
> col1='something' LIMIT 1 OFFSET 2)
> 
> and in the second part should be values of the hits
> 
>  SELECT (DISTINCT(col1,col2,col3)) FROM mytable where col1='something' LIMIT 
> 1 OFFSET 2
> 
> is it possible to solve this with one query I want to avoid having to apply 
> first query.count() and then query.all() to get results is this possible to 
> do this with one query.
> thanks
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/sqlalchemy/-/xr5fGu1B0yoJ.
> 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