Hmm, I was thinking in labeling this evening. I'll try tomorrow when
I get to work and then try this alternative. Maybe it works and avoids
my workaround :) 

Thanks Mike. 

Best regards, 

Richard. 

Em
2013-04-25 19:20, Michael Bayer escreveu: 

> using explicit labels is
the best approach to bypass SQLA's labeling schemes, such as this
example: 
> 
> from sqlalchemy import * 
> from sqlalchemy.orm import *

> from sqlalchemy.ext.declarative import declarative_base 
> Base =
declarative_base() 
> class A(Base): 
> __tablename__ = 'a' 
> id =
Column(Integer, primary_key=True) 
> x = Column(Integer) 
> y =
Column(Integer) 
> e = create_engine("sqlite://", echo=True) 
>
Base.metadata.create_all(e) 
> sess = Session(e) 
> sess.add_all([ 
>
A(x=1, y=2), 
> A(x=2, y=5), 
> A(x=3, y=3), 
> ]) 
> sess.commit() 
>
stmt = select([A.id, A.x, A.y, (A.x + A.y).label('xplusy')]) 
> print
sess.query(A, stmt.c.xplusy).from_statement(stmt).all() 
> 
> On Apr 25,
2013, at 12:47 PM, Richard Gerd Kuesters <rich...@humantech.com.br [37]>
wrote: 
> 
>> Yeah, well, it is a select but didn't work. I also made
another select on top of it (to be sure), but the "error" persists
(could not locate column ...).
>> 
>> Nevermind about it, I think it's
not a question of good usage of SA I think :)
>> 
>> Thanks for your
help!
>> 
>> Cheers,
>> Richard.
>> 
>> On 04/25/2013 01:22 PM, Michael
Bayer wrote: 
>> 
>>> if the original "q" is a select(), this should
work: 
>>> query(MyClass, q.c.somecol,
q.c.someothercol).from_statement(q) 
>>> if not then I guess I'll screw
around with it to see what works. 
>>> 
>>> On Apr 25, 2013, at 10:37
AM, Richard Gerd Kuesters <rich...@humantech.com.br [28]> wrote: 
>>>

>>>> Yup, I agree with you, but things are a little out of hand for me
to use ORM-level queries. I'll see what I can do ...
>>>> 
>>>> Thanks!
:)
>>>> Cheers,
>>>> Richard.
>>>> 
>>>> On 04/25/2013 11:31 AM, Michael
Bayer wrote: 
>>>> 
>>>>> you'd need to organize things differently for
the column grabbing to work out. 
>>>>> I'd advise producing the query
using ORM-level Query in the first place so that you don't need to use
from_statement(), which is really a last resort system. 
>>>>> 
>>>>> On
Apr 25, 2013, at 10:27 AM, Richard Gerd Kuesters
<rich...@humantech.com.br [19]> wrote: 
>>>>> 
>>>>>> Well, not the
desired result ... Now things justs blows :-) 
>>>>>> 
>>>>>>
SQLALCHEMY.EXC.NOSUCHCOLUMNERROR: "COULD NOT LOCATE COLUMN IN ROW FOR
COLUMN 'ANON_1.LEVEL'"
>>>>>> 
>>>>>> Cheers,
>>>>>> Richard.
>>>>>>

>>>>>> On 04/25/2013 11:03 AM, Michael Bayer wrote: 
>>>>>> 
>>>>>>>
why not just say session.query(MyObj, q.alias()) ? creating ad-hoc
mappers is relatively expensive. 
>>>>>>> 
>>>>>>> On Apr 25, 2013, at
8:56 AM, Richard Gerd Kuesters <rich...@humantech.com.br [10]> wrote:

>>>>>>> 
>>>>>>>> Well, probably nevermind because I made a workaround
that satisfies me (may not be elegant, but that's OK).
>>>>>>>>

>>>>>>>> Basically, I created the "o" type a little different: "o =
type('MyObjExt', (Base,), {'__table__':q.alias('q')})" and append it to
the query like: "session.query(MyObj,
o).from_statement(q).all()"
>>>>>>>> 
>>>>>>>> Okay, now it returns a
typle, but at least I don't have to make a second query :)
>>>>>>>>

>>>>>>>> Cheers,
>>>>>>>> Richard.
>>>>>>>> 
>>>>>>>> On 04/25/2013
09:41 AM, Richard Gerd Kuesters wrote: 
>>>>>>>> 
>>>>>>>>> Hi
all,
>>>>>>>>> 
>>>>>>>>> I've been playing with "sqla_hierarchy" from
https://github.com/marplatense/sqla_hierarchy [1] .
>>>>>>>>> 
>>>>>>>>>
The problem is: the returned query appends 3 columns: level (Integer),
is_leaf (Boolean) and connect_path (pg ARRAY).
>>>>>>>>> 
>>>>>>>>> So
far, so good. If I execute the query using
"session.execute(q).fetchall()", it works like a charm. But, as we know,
"session.execute" returns a RowProxy, not objects. Using
"session.query(MyObj).from_statement(q).all()", I'm able to get my
mapped objects, but without the extra columns that would make me very
pleased (level, is_leaf, connect_path). Is there a way to get around
this?
>>>>>>>>> 
>>>>>>>>> I have done testings using "o =
type('MyObjExt', (MyObj,), {'__table__': q}" and them use it on the
session.query, *but* it looses foreign key references - or, well, I
don't know how to "explain" this to the mapper (?), since MyObj is
polymorphic (probably the pitfall?).
>>>>>>>>> 
>>>>>>>>> Thanks for
your time and help.
>>>>>>>>> 
>>>>>>>>> Best regards,
>>>>>>>>>
Richard.
>>>>>>>>> -- 
>>>>>>>>> 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 [2].
>>>>>>>>> To post
to this group, send email to sqlalchemy@googlegroups.com [3].
>>>>>>>>>
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en
[4].
>>>>>>>>> For more options, visit
https://groups.google.com/groups/opt_out [5].
>>>>>>>> -- 
>>>>>>>> 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 [6].
>>>>>>>> To post to this
group, send email to sqlalchemy@googlegroups.com [7].
>>>>>>>> Visit
this group at http://groups.google.com/group/sqlalchemy?hl=en
[8].
>>>>>>>> For more options, visit
https://groups.google.com/groups/opt_out [9].
>>>>>>> -- 
>>>>>>> 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 [11].
>>>>>>> To post to this
group, send email to sqlalchemy@googlegroups.com [12].
>>>>>>> Visit
this group at http://groups.google.com/group/sqlalchemy?hl=en
[13].
>>>>>>> For more options, visit
https://groups.google.com/groups/opt_out [14].
>>>>>> -- 
>>>>>> 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 [15].
>>>>>> To post to this
group, send email to sqlalchemy@googlegroups.com [16].
>>>>>> Visit this
group at http://groups.google.com/group/sqlalchemy?hl=en [17].
>>>>>>
For more options, visit https://groups.google.com/groups/opt_out
[18].
>>>>> -- 
>>>>> 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 [20].
>>>>> To post to this
group, send email to sqlalchemy@googlegroups.com [21].
>>>>> Visit this
group at http://groups.google.com/group/sqlalchemy?hl=en [22].
>>>>> For
more options, visit https://groups.google.com/groups/opt_out [23].
>>>>
-- 
>>>> 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 [24].
>>>> To post to this
group, send email to sqlalchemy@googlegroups.com [25].
>>>> Visit this
group at http://groups.google.com/group/sqlalchemy?hl=en [26].
>>>> For
more options, visit https://groups.google.com/groups/opt_out [27].
>>>
-- 
>>> 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 [29].
>>> To post to this group,
send email to sqlalchemy@googlegroups.com [30].
>>> Visit this group at
http://groups.google.com/group/sqlalchemy?hl=en [31].
>>> For more
options, visit https://groups.google.com/groups/opt_out [32].
>> -- 
>>
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 [33].
>> To post to this group,
send email to sqlalchemy@googlegroups.com [34].
>> Visit this group at
http://groups.google.com/group/sqlalchemy?hl=en [35].
>> For more
options, visit https://groups.google.com/groups/opt_out [36].
> 
> -- 
>
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 post to this group, send
email to sqlalchemy@googlegroups.com.
> Visit this group at
http://groups.google.com/group/sqlalchemy?hl=en [38].
> For more
options, visit https://groups.google.com/groups/opt_out [39].



Links:
------
[1] https://github.com/marplatense/sqla_hierarchy
[2]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[3]
mailto:sqlalchemy@googlegroups.com
[4]
http://groups.google.com/group/sqlalchemy?hl=en
[5]
https://groups.google.com/groups/opt_out
[6]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[7]
mailto:sqlalchemy@googlegroups.com
[8]
http://groups.google.com/group/sqlalchemy?hl=en
[9]
https://groups.google.com/groups/opt_out
[10]
mailto:rich...@humantech.com.br
[11]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[12]
mailto:sqlalchemy@googlegroups.com
[13]
http://groups.google.com/group/sqlalchemy?hl=en
[14]
https://groups.google.com/groups/opt_out
[15]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[16]
mailto:sqlalchemy@googlegroups.com
[17]
http://groups.google.com/group/sqlalchemy?hl=en
[18]
https://groups.google.com/groups/opt_out
[19]
mailto:rich...@humantech.com.br
[20]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[21]
mailto:sqlalchemy@googlegroups.com
[22]
http://groups.google.com/group/sqlalchemy?hl=en
[23]
https://groups.google.com/groups/opt_out
[24]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[25]
mailto:sqlalchemy@googlegroups.com
[26]
http://groups.google.com/group/sqlalchemy?hl=en
[27]
https://groups.google.com/groups/opt_out
[28]
mailto:rich...@humantech.com.br
[29]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[30]
mailto:sqlalchemy@googlegroups.com
[31]
http://groups.google.com/group/sqlalchemy?hl=en
[32]
https://groups.google.com/groups/opt_out
[33]
mailto:sqlalchemy+unsubscr...@googlegroups.com
[34]
mailto:sqlalchemy@googlegroups.com
[35]
http://groups.google.com/group/sqlalchemy?hl=en
[36]
https://groups.google.com/groups/opt_out
[37]
mailto:rich...@humantech.com.br
[38]
http://groups.google.com/group/sqlalchemy?hl=en
[39]
https://groups.google.com/groups/opt_out

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to