比较 timpestamps 与 MySql 中的 NULL 时间戳



我有一个有列last_crawled_article_at timestamp default NULL的表

。当我尝试使用WHERE子句进行更新时,我注意到了一个问题,例如:

UPDATE feed
SET last_crawled_article_at=?, last_captured_id=?
WHERE
feed = ? AND
last_crawled_article_at < ?

如果last_crawled_article_atNULL更新永远不会成功,则没有任何行包含大于NULLlast_crawled_article_at

如果我有一个带有时间戳NULL条目的表,并且我执行下一个查询:

SELCT FROM feed WHERE last_crawled_article_at < '2018-01-01 00:00:00'

Mysql 不返回任何内容。

我解决这种行为的方法是增加last_crawled_article_at0000-00-00 00:00:00

我的问题是,为什么lt时间戳范围查询不返回具有NULL值的条目?

建议以某种方式不要使用默认NULLtimestamp字段?

如果还想更新空值,则必须添加or last_crawled_article_at is null

UPDATE feed
SET last_crawled_article_at=?, last_captured_id=?
WHERE
feed = ? AND
(last_crawled_article_at < ? or last_crawled_article_at is null)

最新更新