sqlite 的 tsrange 或 daterange?

tsrange or daterange for sqlite?

是否有等同于 tsrangedaterange 的数据类型(或者实际上是 PostgreSQL 中可用的任何 range types),例如sqlite?

如果不是,最好的解决方法是什么?

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

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

如@a_horse_with_no_name所述,"You would typically use two columns of that type that store the start and end value of the range"。如果您想按时间间隔进行数据库计算,这确实会有点棘手。但此资源可能会以 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 数据库进行编程变得有趣。