mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
SQLite: param mapping a DateTime value for use in a WHERE comparison clause involving a DATE (TEXT) column causes incorrect/inconsistent results #7495
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @savemetenminutes on GitHub (Apr 7, 2025).
Bug Report
Summary
According to https://www.sqlite.org/datatype3.html#date_and_time_datatype there is no discrete data type for storing DATE or DATETIME values. Instead all values are treated as TEXT for all purposes. When it comes to comparisons, this becomes a problem (see "How to reproduce").
Current behavior
A DATE column value of '2025-05-31' is less than '2025-05-31 00:00:00'
Expected behavior
There are two possibilities to alleviate this issue.
...or (partial stack trace again):
...but obviously the logic would need to be depepndent on the platform. Tested in MySQL and MariaDB, these comparisons work as expected (the DATE value is assumed to refer to time 00:00:00 for purposes of comparison).
I would assume this is a much less performant approach. OTOH this is consistent with the general SQL behavior (I'm yet to test this in PostgreSQL and SQL Server) where the comparison is performed more accurately and satisfies the conditions
'2025-05-31 00:00:01' > '2025-05-31' (this one would fail using the 1. approach as dropping the time part 00:00:00 would make the two strings equal)
'2025-05-31 00:00:00' = '2025-05-31'
How to reproduce
(empty result set)
(empty result set)