【发布时间】:2016-09-01 00:02:24
【问题描述】:
SQLite 并没有真正的日期列。您可以将日期存储为 ISO-8601 字符串、自纪元以来的整数秒数或儒略日数。在我使用的表格中,我希望我的日期是人类可读的,所以我选择使用 ISO-8601 字符串。
假设我想查询所有日期在今天之后的记录。 ISO-8601 字符串将正确排序,因此我应该能够将字符串与今天日期的 ISO-8601 字符串进行比较。
但是,我认为无法使用 F# SqlProvider 类型提供程序进行比较。我希望这只是我缺乏 F# 查询表达式知识的反映。
例如,我做不到:
query {
for calendarEntry in dataContext.``[main].[calendar_entries]`` do
where (calendarEntry.date >= System.DateTime.Today.ToString("yyyy-MM-dd hh:mm:ss"))
... }
我明白了:
The binary operator GreaterThanOrEqual is not defined for the types 'System.String' and 'System.String'.
我也不能做任何变化:
query {
for calendarEntry in dataContext.``[main].[calendar_entries]`` do
where (calendarEntry.date.CompareTo(System.DateTime.Today.ToString("yyyy-MM-dd hh:mm:ss")) >= 0)
... }
我明白了:
Unsupported expression. Ensure all server-side objects appear on the left hand side of predicates. The In and Not In operators only support the inline array syntax.
有人知道我可以如何在 where 子句中进行字符串比较吗?似乎我在查询中进行过滤的唯一选择是将 seconds-since-epoch 存储在数据库中并使用整数比较。
【问题讨论】: