When using psycopg2 as the database connector specified in a DATABASES constant in settings.py, how do raw SQL queries get handled? When you use django.db.connection and cursor.execute(), does it use Django's classes to handle things, or psycopg2s?
Here's an example constant:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'webdev',
'USER': 'someone',
'PASSWORD': 'soopersekrit',
'HOST': 'localhost',
'PORT': '5432',
}
}
and example raw query setup:
from django.db import connection
with connection.cursor() as cursor:
sql_statement = f'''
UPDATE cart c SET
apples = {apples_count},
WHERE c.id = {table_row_pk}
'''
cursor.execute(sql=sql_statement)