将时间戳与 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更新从来没有成功,由于没有包含任何行last_crawled_article_at大于NULL

如果我有一个带有时间戳的条目的表,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值的条目

以某种方式建议不要使用默认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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章