summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql_psycopg2/operations.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2015-03-07 13:20:29 -0800
committerTim Graham <timograham@gmail.com>2015-06-02 08:49:10 -0400
commit44f3ee77166bd5c0e8a4604f2d96015268dce100 (patch)
tree733d47ee8d00d3934ae86d8b26275ad4fde4d371 /django/db/backends/postgresql_psycopg2/operations.py
parent076a63e672370ff1735e7942cd1ae0990bcbd263 (diff)
downloaddjango-44f3ee77166bd5c0e8a4604f2d96015268dce100.tar.gz
Fixed #9596 -- Added date transform for DateTimeField.
Diffstat (limited to 'django/db/backends/postgresql_psycopg2/operations.py')
-rw-r--r--django/db/backends/postgresql_psycopg2/operations.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql_psycopg2/operations.py
index 65d6c9154b..866e2ca38b 100644
--- a/django/db/backends/postgresql_psycopg2/operations.py
+++ b/django/db/backends/postgresql_psycopg2/operations.py
@@ -32,26 +32,26 @@ class DatabaseOperations(BaseDatabaseOperations):
# http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
- def datetime_extract_sql(self, lookup_type, field_name, tzname):
+ def _convert_field_to_tz(self, field_name, tzname):
if settings.USE_TZ:
field_name = "%s AT TIME ZONE %%s" % field_name
params = [tzname]
else:
params = []
- # http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
- if lookup_type == 'week_day':
- # For consistency across backends, we return Sunday=1, Saturday=7.
- sql = "EXTRACT('dow' FROM %s) + 1" % field_name
- else:
- sql = "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
+ return field_name, params
+
+ def datetime_cast_date_sql(self, field_name, tzname):
+ field_name, params = self._convert_field_to_tz(field_name, tzname)
+ sql = '(%s)::date' % field_name
+ return sql, params
+
+ def datetime_extract_sql(self, lookup_type, field_name, tzname):
+ field_name, params = self._convert_field_to_tz(field_name, tzname)
+ sql = self.date_extract_sql(lookup_type, field_name)
return sql, params
def datetime_trunc_sql(self, lookup_type, field_name, tzname):
- if settings.USE_TZ:
- field_name = "%s AT TIME ZONE %%s" % field_name
- params = [tzname]
- else:
- params = []
+ field_name, params = self._convert_field_to_tz(field_name, tzname)
# http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
sql = "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
return sql, params