我有一个有列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_at
NULL
更新永远不会成功,则没有任何行包含大于NULL
last_crawled_article_at
。
如果我有一个带有时间戳NULL
条目的表,并且我执行下一个查询:
SELCT FROM feed WHERE last_crawled_article_at < '2018-01-01 00:00:00'
Mysql 不返回任何内容。
我解决这种行为的方法是增加last_crawled_article_at
0000-00-00 00:00:00
我的问题是,为什么lt
时间戳范围查询不返回具有NULL
值的条目?
建议以某种方式不要使用默认NULL
timestamp
字段?
如果还想更新空值,则必须添加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)