0

I find ResultProxy more convenient to use than ORM results in some cases (by the docs I understand that I could iterate the columns in a full table). I tried this:

query = session.query(Table1)
results = [ResultProxy(a) for a in query]

... but fails with:

AttributeError: 'Table1' object has no attribute 'dialect'

2 Answers 2

1

you can't just instantiate a ResultProxy like that, it is specific to DBAPI cursors as well as contextual information regarding how the statement was constructed. Use Session.execute() to get one from query.statement. It wouldn't be hard to add a method to Query to provide the ResultProxy it works with directly, though.

Sign up to request clarification or add additional context in comments.

5 Comments

How, then, do I get the ResultProxy it works with? Or any other way to fetch simple key-value pairs.
result_proxy = Session.execute(query.statement)
that raises this exception "NoReferencedTableError: Foreign key associated with column 'seguimientos.empresa' could not find table 'datos' with which to generate a foreign key to target column 'id'"
would need a succinct and complete test case illustrating the query in question. that issue appears like something happening not during the query but within the mapper configuration stage.
True. Thanks, I found the error. It works now. However I found an easier way to get what I wanted. I will put it as an answer below.
0

Quick answer:

conn = engine.connect()
result_proxy = conn.execute(query.selectable)

Docs here.

You can also get a column index by its name...

col_index = query.selectable.columns.keys().index(id_column_name)

... and then get the result by its index:

first_row_col_content = query.all()[0][col_index]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.