summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/operations.py
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2009-02-08 05:08:06 +0000
committerKaren Tracey <kmtracey@gmail.com>2009-02-08 05:08:06 +0000
commitaddd3df3bd39730cd82c52d9726c9b7dbf1bdb8f (patch)
treee648cbb129dfd103af1d278aaafc0a7007ce95ea /django/db/backends/postgresql/operations.py
parent0326574d0ecf2eeded92d66855822dd2e602297f (diff)
downloaddjango-addd3df3bd39730cd82c52d9726c9b7dbf1bdb8f.tar.gz
Fixed #7672 -- Added a 'week_day' lookup type. Many thanks to Ross Poulton for the proposal and implementation on all built-in database backends..
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9818 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/postgresql/operations.py')
-rw-r--r--django/db/backends/postgresql/operations.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/operations.py b/django/db/backends/postgresql/operations.py
index 9f221b3822..45b17b5778 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -26,7 +26,12 @@ class DatabaseOperations(BaseDatabaseOperations):
def date_extract_sql(self, lookup_type, field_name):
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
- return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
+ if lookup_type == 'week_day':
+ # Using EXTRACT(), PostgreSQL days are indexed as Sunday=0, Saturday=6.
+ # If we instead us TO_CHAR, they're indexed with Sunday=1, Saturday=7
+ return "TO_CHAR(%s, 'D')" % field_name
+ else:
+ return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
def date_trunc_sql(self, lookup_type, field_name):
# http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC