Skip to content

Instantly share code, notes, and snippets.

@wellic
Forked from tkrajina/django_raw_sql_without_model.py
Last active December 26, 2017 08:23
Show Gist options
  • Save wellic/3b67185b34cdb70a1ec61051e4f2c66c to your computer and use it in GitHub Desktop.
Save wellic/3b67185b34cdb70a1ec61051e4f2c66c to your computer and use it in GitHub Desktop.
Django raw sql without model
from django.db import connection
# If using cursor without "with" -- it must be closed explicitly:
with connection.cursor() as cursor:
cursor.execute('select column1, column2, column3 from table where aaa=%s', [5])
for row in cursor.fetchall():
print row[0], row[1], row[3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment