Skip to content

Commit

Permalink
Implemented QuerySet.datetimes on PostgreSQL.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Feb 13, 2013
1 parent 0c829c2 commit f6800fd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions django/db/backends/postgresql_psycopg2/operations.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals

from django.conf import settings
from django.db.backends import BaseDatabaseOperations


Expand Down Expand Up @@ -36,6 +37,22 @@ def date_trunc_sql(self, lookup_type, field_name):
# http://www.postgresql.org/docs/8.0/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):
if settings.USE_TZ:
field_name = "%s AT TIME ZONE %%s" % field_name
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
if lookup_type == 'week_day':
# For consistency across backends, we return Sunday=1, Saturday=7.
return "EXTRACT('dow' FROM %s) + 1" % field_name
else:
return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)

def datetime_trunc_sql(self, lookup_type, field_name):
if settings.USE_TZ:
field_name = "%s AT TIME ZONE %%s" % field_name
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)

def deferrable_sql(self):
return " DEFERRABLE INITIALLY DEFERRED"

Expand Down

0 comments on commit f6800fd

Please sign in to comment.