是否有相当于 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/