sqlite - sqlite 的 tsrange 或 daterange ?

标签 sqlite date-range range-types

是否有相当于 tsrange 或 daterange 的数据类型(或者实际上 PostgreSQL 中可用的 range types 中的任何一个),例如SQLite?

如果没有,解决这个问题的最佳方法是什么?

最佳答案

抱歉,SQLite 中只有 5 种数据类型:https://www.sqlite.org/datatype3.html

NULL、INTEGER、REAL、TEXT 和 BLOB。还有数字。

正如 @ a_horse_with_no_name 提到的,“您通常会使用该类型的两列来存储范围的开始值和结束值”。如果您想按时间间隔进行数据库计算,这确实会有点棘手。但此资源可能会被发现为 run-time loadable extension .

您通常会使用该类型的两列来存储范围的开始值和结束值。 – a_horse_with_no_name 42 分钟前

谨慎行事; SQLite 对每种数据类型的接受程度相当宽容:

SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container. The dynamic type system of SQLite is backwards compatible with the more common static type systems of other database engines in the sense that SQL statements that work on statically typed databases should work the same way in SQLite. However, the dynamic typing in SQLite allows it to do things which are not possible in traditional rigidly typed databases.

这意味着您可以在整数字段中添加文本;如果文本是整数,那就没问题。如果不是,那也没关系。它将被存储并在检索时返回给您。不同之处在于,如果它可以转换为整数,那么它就会转换为整数,并且您将返回一个整数。如果无法转换,您将返回一个文本字符串。这可能会让 SQLite 数据库编程变得有趣。

关于sqlite - sqlite 的 tsrange 或 daterange ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54142570/

相关文章:

python - Pandas date_range() 表示月中和月末

sqlite - sqlite MvvmCross GetConnectionWithLock发生了什么?

Android:从将数据存储在列表中过渡到使用 SQLite

javascript - 在 JQuery Datepicker 中突出显示开始日期和结束日期之间的日期

python - Pandas : How to sum column values over a date range

sql - 如何使用 NOW() 函数作为范围的上限?

android - 在android中按月从数据库中获取值

python - 有没有办法将数据库中的列标题用作Python中的变量?

PostgreSQL tsrange: lower_inf ('(-infinity,today)'::tsrange) 为假是否正确?

sql - 在 PostgreSQL 中使用 EXCLUDE 防止相邻/重叠的条目