Initially I tried to remain solely in ORM constructs, I only broke down and 
used the SQL expressions after hitting a wall.
 
A little more specifically: 
when I try:
session.query (part1).all ()   
I receive an array of class 'sqlalchemy.util._collections.result'   while I 
was expecting an array of class T as the part1 cte actually creates a set 
of T.   

Is there a way to let SA that result of the session.query(T).cte(...) is 
actually a set of T?
Is  there a way to convert 'result' tuples into class T?

Thanks




 



On Tuesday, November 10, 2020 at 5:46:32 AM UTC-8 Mike Bayer wrote:

> I would advise against using from_statement().   the Query object supports 
> cte() and subqueries directly, see the example at 
> https://docs.sqlalchemy.org/en/13/orm/query.html?highlight=query%20cte#sqlalchemy.orm.query.Query.cte
>
> alternatively if you are using 1.4 beta1 then you can use 
> session.execute() directly using a select() object.
>
>
>
> On Tue, Nov 10, 2020, at 2:37 AM, kris wrote:
>
>
> I need to query over a  table mapped to class T, 
> I usually use session.query (T), however I am using two cte's              
>                                           
> part0 =  ... cte('part0')
> part1 = ... cte('part1')                                                  
>                                                                       part2 
> = ... cte('aprt2')                                                          
>                                                                   allparts 
> = union (part1.select(), part2.select())                                    
>                                               
> session.query (allparts)  .. returns row record but I need it to return 
> objects of type T?     
>
> I have tried using   q1 = session.query(T).from_statement (allnodes) 
> which appears to convert and create objects of T, However, 
> I cannot filter or order_by
>
> I have tried using the sql epxression level:
> n = allparts.alias()
>  DBSession.query (T).from_statement (select ([n]).where (...).order_by 
> (...)).all()
> or 
>  DBSession.query(T).from_statement(DBSession.query 
> (n).filter(...).order_by(...).statement).
>
> but I get NoSuchColumnError: "Could not locate column in row for column 
> 'T.id'"
>
> Is there a way to let SA know how map the columns of the select expression 
> to an object?
>
> Thanks.
>
>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/7f27eaff-1f0e-40a9-a225-464414d04041n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/7f27eaff-1f0e-40a9-a225-464414d04041n%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/c2031a38-e4ed-40a6-a02b-4ff5b9e8c496n%40googlegroups.com.

Reply via email to