mirror of
https://github.com/django/django.git
synced 2025-10-08 09:40:35 +00:00
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
This commit is contained in:
parent
d4ddc06021
commit
b1c543d091
4 changed files with 27 additions and 3 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue