저는 파이썬의 db-api fetchone 대 fetchmany 대 fetchall에 관한 몇몇 동료들과 토론을했습니다.Python db-api : fetchone 대 fetchmany 대 fetchall
각각의 유스 케이스는 내가 사용하고있는 db-api의 구현에 따라 다르지만 일반적으로 fetchone 대 fetchmany 대 fetchall의 사용 사례는 무엇입니까?
다른 말로 표현하면 다음과 같습니다. 아니면 다른 것들보다 선호되는 이들 중 하나입니까? 그렇다면 어떤 상황에서?
cursor.execute("SELECT id, name FROM `table`")
for i in xrange(cursor.rowcount):
id, name = cursor.fetchone()
print id, name
cursor.execute("SELECT id, name FROM `table`")
result = cursor.fetchmany()
while result:
for id, name in result:
print id, name
result = cursor.fetchmany()
cursor.execute("SELECT id, name FROM `table`")
for id, name in cursor.fetchall():
print id, name
대부분의 메모리를 사용하는 fetchall()에서 이러한 메모리 사용량에 차이가 있습니다. –
이 세 가지 가져 오기 명령은 나도 내 머리를 긁적이게했다. 해당 Python이 myServer 서버와 동일한 서버에서 실행되고 있다면 어떻게 될까요? – SMGreenfield