Re: [sqlalchemy] Re: all

2012-07-12 Thread Michael Bayer

On Jul 11, 2012, at 8:27 PM, Gunnlaugur Briem wrote:

 Hi burgiduroy,
 
 On Wednesday, 11 July 2012 15:24:59 UTC, burgiduroy wrote:
 Are there any performance difference between the two?
 
 for row in  query_object.all():
do_something()
 
 AND
 
 for row in query_object:
do_something()
 
 The first fetches and processes all rows in one go before executing the loop 
 body. The second streams them in.
 
 How much that really matters depends on the DBAPI (it may fetch all rows in 
 one go anyway), and maybe on how heavy the object mapping is ... and on 
 whether you end up exiting your loop early (and so avoid processing the rest 
 unnecessarily).

Well, assuming this is an ORM Query, the Query object internally processes all 
the rows before yielding them regardless, unless you used the yield_per() 
method to configure that it should process them in batches.   Unfortunately the 
Query can't unconditionally yield rows at a time due to the fact that the same 
mapped object can be present multiple times across many rows, as a result of 
explicit joins as well as loads of related collections, and mapped objects are 
mutable. 

So normally there's no real difference in memory usage between iter(query) and 
query.all(), and none for performance except for the small overhead of the 
extra list(self) that query.all() uses.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: all

2012-07-12 Thread burgiduroy
So which is the best practice? for row in query or  for row in
query.all()

On Thu, Jul 12, 2012 at 8:54 PM, Michael Bayer mike...@zzzcomputing.comwrote:


 On Jul 11, 2012, at 8:27 PM, Gunnlaugur Briem wrote:

 Hi burgiduroy,

 On Wednesday, 11 July 2012 15:24:59 UTC, burgiduroy wrote:

 Are there any performance difference between the two?

 for row in  query_object.all():
do_something()

 AND

 for row in query_object:
do_something()


 The first fetches and processes all rows in one go before executing the
 loop body. The second streams them in.

 How much that really matters depends on the DBAPI (it may fetch all rows
 in one go anyway), and maybe on how heavy the object mapping is ... and on
 whether you end up exiting your loop early (and so avoid processing the
 rest unnecessarily).


 Well, assuming this is an ORM Query, the Query object internally processes
 all the rows before yielding them regardless, unless you used the
 yield_per() method to configure that it should process them in batches.
 Unfortunately the Query can't unconditionally yield rows at a time due to
 the fact that the same mapped object can be present multiple times across
 many rows, as a result of explicit joins as well as loads of related
 collections, and mapped objects are mutable.

 So normally there's no real difference in memory usage between iter(query)
 and query.all(), and none for performance except for the small overhead of
 the extra list(self) that query.all() uses.

 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sqlalchemy?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: all

2012-07-11 Thread Gunnlaugur Briem
Hi burgiduroy,

On Wednesday, 11 July 2012 15:24:59 UTC, burgiduroy wrote:

 Are there any performance difference between the two?

 for row in  query_object.all():
do_something()

 AND

 for row in query_object:
do_something()


The first fetches and processes all rows in one go before executing the 
loop body. The second streams them in.

How much that really matters depends on the DBAPI (it may fetch all rows in 
one go anyway), and maybe on how heavy the object mapping is ... and on 
whether you end up exiting your loop early (and so avoid processing the 
rest unnecessarily).

Regards,

Gulli

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/rtdpsUfOa1QJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: *all* *new* *tutorials* !!!!

2007-08-07 Thread Alexandre CONRAD

This *IS* some piece of work ! Mike, you are the One ! :)

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: *all* *new* *tutorials* !!!!

2007-08-06 Thread Arun Kumar PG
Cool. thx Michael!

On 8/7/07, Michael Bayer [EMAIL PROTECTED] wrote:


 Hi gang -

 The documentation for 0.4 is undergoing tremendous changes, and is now
 released, in its almost-there format, at
 http://www.sqlalchemy.org/docs/04/
 .  The goal with these docs is not just to update to new 0.4
 paradigms, but to also raise the bar for accuracy and clarity.

 Of major note is that the datamapping and sql construction sections,
 as well as the old tutorial, have been entirely replaced by two new
 and very comprehensive tutorials, one targeted at ORM and the other at
 SQL Expression Language.  Both have no prerequisites to start, they
 each can be the first thing you ever read about SQLAlchemy.  Both are
 also fully executable doctest format, so they are guaranteed not to
 have my usual array of mistakes.

 Also here is a rewritten mapper configuration document to replace
 advanced datamapping.  It includes clearer, up-to-date, and more
 correct examples of virtually every major mapper pattern we have,
 including all the new stuff like dynamic relations.

 With recently updated engine and metadata sections, the only major
 section left is sessions, which already includes information about
 the new autoflush and transactional sessions, as well as two-phase
 and SAVEPOINT recipes...I hope to simplify some of the older content
 here as well as standardize on the new sessionmaker function and its
 cousin, scoped_session, which replaces SessionContext as well as
 assignmapper (both are deprecated in 0.4).

 I hope everyone can check out the docs, come back with feedback/
 corrections/questions, and start getting ready for 0.4 !

 - mike


 



-- 
Cheers,

- A

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: all() or list() ?

2007-08-02 Thread Mike Orr

On 8/1/07, Gaetan de Menten [EMAIL PROTECTED] wrote:

 On 8/1/07, Alexandre CONRAD [EMAIL PROTECTED] wrote:

  I'm realizing that I've been using .list() to query objects. But all the
  examples in the docs talk about .all().
 
  What's the difference ? Should I switch to .all() rather than .list() ?

  Will list be deprecated in 0.4 ?

 Exactly. list() is the old way, all() is the 0.4 way.

.list() is the old new way, or short-lived new way.  .all() is the
real new way.

-- 
Mike Orr [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: all() or list() ?

2007-08-01 Thread Gaetan de Menten

On 8/1/07, Alexandre CONRAD [EMAIL PROTECTED] wrote:

 I'm realizing that I've been using .list() to query objects. But all the
 examples in the docs talk about .all().

 What's the difference ? Should I switch to .all() rather than .list() ?

 Will list be deprecated in 0.4 ?

Exactly. list() is the old way, all() is the 0.4 way.

-- 
Gaƫtan de Menten
http://openhex.org

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: all() or list() ?

2007-08-01 Thread Alexandre CONRAD

Gaetan de Menten wrote:
What's the difference ? Should I switch to .all() rather than .list() ?
Will list be deprecated in 0.4 ?
 
 Exactly. list() is the old way, all() is the 0.4 way.

Thanks Gaetan, I'll clean up my code to be compliant with 0.4.

Regards,
-- 
Alexandre CONRAD


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---