Skip to content

Instantly share code, notes, and snippets.

@tobrien
Created October 26, 2012 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobrien/3959201 to your computer and use it in GitHub Desktop.
Save tobrien/3959201 to your computer and use it in GitHub Desktop.
Executing a SQLAlchemy Query against Akiban's Nested Resultsets
from sqlalchemy_akiban import nested
stmt = nested([order.c.ordernum, order.c.timestamp]).\
where(order.c.customer_id == customer.c.id)
stmt = select([customer.c.name, stmt.label('orders')])
for customer_row in connection.execute(stmt):
print "customer name:", customer_row['name']
for order_row in customer_row['orders']:
print "ordernum:", order_row['ordernum']
print "timestamp:", order_row['timestamp']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment