SQLite CREATE TABLE:DEFAULT 子句
如果您的 SQLite 创建表语句包含如下行:
CREATE TABLE alerts ( -- ... alert_created_at text default current_timestamp )
current_timestamp
将替换为格式为2025-05-08 22:19:33
UTC 时间戳。您还可以使用current_time
表示HH:MM:SS
,使用current_date
表示YYYY-MM-DD
,同样使用 UTC。
在此发布此内容是因为我之前没有注意到默认为 UTC,这是一个有用的细节。这也是强烈支持YYYY-MM-DD HH:MM:SS
作为与 SQLite 一起使用的字符串格式,否则 SQLite 不会提供正式的日期时间类型。
原文: https://simonwillison.net/2025/May/8/sqlite-create-table-default-timestamp/#atom-everything