#33517: Extracting seconds also returns fractional seconds on PostgreSQL.
-------------------------------------+-------------------------------------
Reporter: Joey Lange | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):
* component: Documentation => Database layer (models, ORM)
* stage: Unreviewed => Accepted
Comment:
Thanks for the report! We should have consistent behavior on all backends.
What do you think about adding `DATE_TRUNC()` in this case? For example:
{{{#!diff
diff --git a/django/db/backends/postgresql/operations.py
b/django/db/backends/postgresql/operations.py
index 399c1b24e7..fd90b95fb8 100644
--- a/django/db/backends/postgresql/operations.py
+++ b/django/db/backends/postgresql/operations.py
@@ -36,6 +36,8 @@ class DatabaseOperations(BaseDatabaseOperations):
return "EXTRACT('isodow' FROM %s)" % field_name
elif lookup_type == 'iso_year':
return "EXTRACT('isoyear' FROM %s)" % field_name
+ elif lookup_type == 'second':
+ return f"EXTRACT('second' FROM DATE_TRUNC('second',
{field_name}))"
else:
return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33517#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.858fcfd60c1dc379bd27ee321642d604%40djangoproject.com.