Forked from tkrajina/django_raw_sql_without_model.py
Created
January 12, 2019 05:39
-
-
Save johnsonc/16694bcca35eae8f98fe059a96b28ae0 to your computer and use it in GitHub Desktop.
Django raw sql without model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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