summaryrefslogtreecommitdiff
path: root/django/core/db/backends/postgresql.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-07-17 20:16:06 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-07-17 20:16:06 +0000
commitb1c543d0910a79f4de93464fa684416c9441f7ce (patch)
treeda8ecbbc61478ad43df060af79da2637b89d89e0 /django/core/db/backends/postgresql.py
parentd4ddc06021a6c39665949111d9e9e9b2c4675ae6 (diff)
Factored out database-specific date_trunc behavior into dbmod.get_date_trunc_sql(). Refs #46
git-svn-id: http://code.djangoproject.com/svn/django/trunk@161 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/db/backends/postgresql.py')
-rw-r--r--django/core/db/backends/postgresql.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/django/core/db/backends/postgresql.py b/django/core/db/backends/postgresql.py
index df7829f683..8a629453b3 100644
--- a/django/core/db/backends/postgresql.py
+++ b/django/core/db/backends/postgresql.py
@@ -63,8 +63,14 @@ def get_last_insert_id(cursor, table_name, pk_name):
def get_date_extract_sql(lookup_type, table_name):
# lookup_type is 'year', 'month', 'day'
+ # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
return "EXTRACT('%s' FROM %s)" % (lookup_type, table_name)
+def get_date_trunc_sql(lookup_type, field_name):
+ # lookup_type is 'year', 'month', 'day'
+ # http://www.postgresql.org/docs/8.0/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
+ return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
+
# Register these custom typecasts, because Django expects dates/times to be
# in Python's native (standard-library) datetime/time format, whereas psycopg
# use mx.DateTime by default.