将朱利安日期列添加到 SQLite 表
这很简单,但我无法从 SQLite FAQ 和 ALTER TABLE
的小插图中弄清楚。
我有一个日期列,但为了找到时差,我需要使用儒略日期,所以我觉得我不妨添加一个儒略日期列,因为我会经常这样做。但我不知道该怎么做。
我已经经历了很多次迭代,但我认为我并没有理解 ALTER TABLE
和 INSERT INTO
命令的 SQLite 哲学。谢谢!
This is easy, but I can't figure it out from the SQLite FAQ and vignette for ALTER TABLE
.
I have a date column, but to find a time difference, I need to use julian dates, so I feel like I might as well add a julian date column because I'll be doing this a lot. But I can't figure out how to do it.
I've gone through a bunch of iterations, but I don't think I'm clicking with the SQLite philosophy of the ALTER TABLE
and INSERT INTO
commands. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法在 SQLite 表中添加计算列。但是您可以使用
VIEW
来做到这一点。You can't add a calculated column in an SQLite table. But you can do that with a
VIEW
.Sqlite 中没有 DATE 或 TIME 类型。您可以自由选择对您有意义的内容。如果只是用于记录的时间戳或其他内容,则 STRING 应该没问题。如果您要做日期时间比较和数学(根据问题),那么 INTEGER 是最好的。
此页面讨论内置函数的使用。如果使用 INTEGER 存储自纪元以来的秒数,则可以使用减法来查找时间差。
There are no DATE or TIME types in Sqlite. You're free to select what makes sense for you. If it's just timestamps for logging or something, STRING should be ok. If you're going to do datetime comparisons and math (which you are according to the question), INTEGER would be best.
This page discuses built-in functions for use. If you use INTEGER to store seconds since epoch, you can use subtraction to find a time difference.