summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/__init__.py8
-rw-r--r--django/db/backends/postgresql_psycopg2/base.py3
-rw-r--r--django/db/backends/postgresql_psycopg2/operations.py3
3 files changed, 13 insertions, 1 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 7674f5c879..6f1f4b9618 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -710,6 +710,14 @@ class BaseDatabaseOperations(object):
"""
raise NotImplementedError
+ def set_time_zone_sql(self):
+ """
+ Returns the SQL that will set the connection's time zone.
+
+ Returns '' if the backend doesn't support time zones.
+ """
+ return ''
+
def sql_flush(self, style, tables, sequences):
"""
Returns a list of SQL statements required to remove all data from
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index 802ebf2b80..0d25129313 100644
--- a/django/db/backends/postgresql_psycopg2/base.py
+++ b/django/db/backends/postgresql_psycopg2/base.py
@@ -190,7 +190,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
# Set the time zone in autocommit mode (see #17062)
self.connection.set_isolation_level(
psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
- self.connection.cursor().execute("SET TIME ZONE %s", [tz])
+ self.connection.cursor().execute(
+ self.ops.set_time_zone_sql(), [tz])
self.connection.set_isolation_level(self.isolation_level)
self._get_pg_version()
connection_created.send(sender=self.__class__, connection=self)
diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql_psycopg2/operations.py
index 949a05c0b6..395cd92047 100644
--- a/django/db/backends/postgresql_psycopg2/operations.py
+++ b/django/db/backends/postgresql_psycopg2/operations.py
@@ -71,6 +71,9 @@ class DatabaseOperations(BaseDatabaseOperations):
return name # Quoting once is enough.
return '"%s"' % name
+ def set_time_zone_sql(self):
+ return "SET TIME ZONE %s"
+
def sql_flush(self, style, tables, sequences):
if tables:
# Perform a single SQL 'TRUNCATE x, y, z...;' statement. It allows