我有一个有列的表 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
更新从来没有成功,由于没有包含任何行last_crawled_article_at
大于NULL
。
如果我有一个带有时间戳的条目的表,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
值的条目?
以某种方式建议不要使用默认timestamp
字段NULL
?
如果您还想更新空值,则必须添加 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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句