Python db-api: fetchone vs fetchmany vs fetchall

前端 未结 3 1775
后悔当初
后悔当初 2020-12-07 14:16

I just had a discussion today with some coworkers about python\'s db-api fetchone vs fetchmany vs fetchall.

I\'m sure the use case for each of these is dependent on

3条回答
  •  日久生厌
    2020-12-07 14:48

    I think it indeed depends on the implementation, but you can get an idea of the differences by looking into MySQLdb sources. Depending on the options, mysqldb fetch* keep the current set of rows in memory or server side, so fetchmany vs fetchone has some flexibility here to know what to keep in (python's) memory and what to keep db server side.

    PEP 249 does not give much detail, so I guess this is to optimize things depending on the database while exact semantics are implementation-defined.

提交回复
热议问题