[DB-SIG] "lists of tuples" vs. "tuples of tuples"

M.-A. Lemburg mal at egenix.com
Mon Feb 2 12:13:54 CET 2015


On 01.02.2015 22:47, Michael Bayer wrote:
> Hi -
> 
> May I get clarification from pep-249 regarding the contract for fetchall() and fetchmany(), as to if it is acceptable and/or recommended that these methods return tuples of tuples, as opposed to lists of tuples?
> 
> In my experience, while tuples and lists are just “sequences” that are immutable / mutable, there is a more subtle semantic distinction between them, in that lists are for variable-length collections of homogenous elements (e.g. rows), whereas tuples are appropriate for fixed-length collections of heterogenous elements (e.g. column values).  
> 
> If this is the case, pep-249’s use of the language "e.g. a list of tuples” leaves this open to interpretation and inconsistency, like so many other things.   I’d like to get some language, at least in email here, that lists are recommended, if this is the case.     Otherwise, I guess it’ll just be another thing for me to suggest for DBAPI-3 :).
> 
> thanks for your attention!

We have made this more general in the DB-API to allow authors to
create e.g. result set objects which implement the sequence API
and row objects which also implement sequence API.

I know several database modules which provide ways to have the
fetch methods return row objects, but I'm not aware of ones which
implement a result set object.

You get the best performance using lists of tuples. Tuple creation
is fast and lists are ideal for variable length storage of objects.

Using tuples for result sets is not a very useful thing to do,
since you typically want to manipulate the result set in the
application.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 02 2015)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> mxODBC Plone/Zope Database Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the DB-SIG mailing list