Hey Mike!

I'm almost there :) The only problem now is with a column that returns a postgres *ARRAY* type.

When labeling is not applied, I get the same error as before:

*sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column 'connect_path'"*

But, when I apply a label on it, another error returns:

*File "/home/richard/.../python2.7/site-packages/sqlalchemy/util/_collections.py", line 684, in unique_list**
**    if hashfunc(x) not in seen**
**TypeError: unhashable type: 'list'*


Any ideas? Perhaps I'm missing something?


Best regards,
Richard.




On 04/25/2013 07:31 PM, Richard Gerd Kuesters wrote:

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 <[email protected] <mailto:[email protected]>> 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 <[email protected] <mailto:[email protected]>> 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 <[email protected] <mailto:[email protected]>> 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 <[email protected] <mailto:[email protected]>> 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 .

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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit 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 [email protected].
To post to this group, send email to [email protected].
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