13๐
โ
As you mention in your question but Iโll reiterate here for future readers: itโs also possible to use explicitly named cursors without bypassing Djangoโs public API:
from django.db import connection, transaction
with transaction.atomic(), connection.cursor() as cur:
cur.execute("""
DECLARE mycursor CURSOR FOR
SELECT *
FROM giant_table
""")
while True:
cur.execute("FETCH 1000 FROM mycursor")
chunk = cur.fetchall()
if not chunk:
break
for row in chunk:
process_row(row)
๐คDavid Wolever
0๐
Cursors should be used inside transactions. You need to define a transaction and to use the cursor inside it.
โ need to be in a transaction to use cursors.
Taken from here.
๐คLajos Arpad
0๐
I was getting this due to isolation_level='AUTOCOMMIT'
in my sqlalchemy.create_engine
.
๐คdavetapley
- How to activate the process queue in "django-background-tasks"
- Django message template tag checking
- South migration: DatabaseOperations has not attribute 'shorten_name'
- Is there any way to use GUIDs in django?
Source:stackexchange.com