you can take the statement and execute it on the connection instead, then 
you'll get tuples with columns.  not sure if there was some way to get this 
through session.execute() directly.



On Tue, Aug 31, 2021, at 5:01 PM, Gord Thompson wrote:
> My memory is failing me. I seem to recall that there was a succinct way to 
> get a 1.4/2.0 ORM query to return individual columns instead of ORM objects. 
> That is, to tell this
> 
> print(session.execute(select(User)).fetchall())
> # [(<__main__.User object at 0x00000090175EC700>,)]
> 
> to return the equivalent of this
> 
> print(session.execute(select(User.id, User.name)).fetchall())
> # [(1, 'Gord')]
> 
> without explicitly naming each attribute (column). A modifier like 
> `.as_columns()` or something like that …?
> 
> Interestingly, if I try to use `*` I only get the first (or maybe the PK) 
> column
> 
> print(session.execute(select(text("*")).select_from(User)).fetchall())
> # [(1,)]
> 
> 
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> --- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/3d1d98e8-a7ac-4748-8cd3-56c32f275644n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/3d1d98e8-a7ac-4748-8cd3-56c32f275644n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/d2f5ecac-4c2f-48ff-adc4-4472d8122e16%40www.fastmail.com.

Reply via email to