On Jul 20, 2010, at 9:39 PM, Lukasz Szybalski wrote:

> 
> Instead of typing manually column names
> ("column1","column2",..."column38" inside the query() I would like to
> use previous query .keys() to list them there....
> 
> Instead doing:
> myresults=session.query('column1','column2','column3').from_statement....
> I would like to do a=session.execute(...)  and then
> myresults=session.query(a.keys()).from_statement(....) where a.keys()
> returns a list of all the column names from the stored procedure, but
> unfortunately passing a list like "a.keys()" gives me an error. If I
> type it in it works fine. How can I pass in these column names ?
> Should I convert a.keys() to dictionary, or some other type?

how is calling query(colmames)...all() significantly different from simply 
saying execute(..).fetchall() ?  you get a list of named-tuple like objects in 
both cases.

Anyway, the column names are not available until you execute your string 
statement and cursor.description is accessed.   So if you really were in the 
mood for this , you could say:

result = Session.execute(stmt)
query = Session.query(*[column(name) for name in 
result.keys()]).instances(result)



> 
> __init__
>    "expected - got '%r'" % column
> sqlalchemy.exc.InvalidRequestError: SQL expression, column, or mapped
> entity expected - got '[u'customer', u'customer_id', u'customer_num',
> u'TransactionDate'......]
> 
> 
> I tried fetchall but when I loop over the rows, I was getting a
> dictionary and instead of doing row.column1, I had to use row[0].
> 
> Thanks,
> Lucas
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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 sqlalch...@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