【问题标题】:How to fix: argument of AND must be type boolean, not type numeric如何解决:AND 的参数必须是布尔类型,而不是数字类型
【发布时间】:2019-06-25 11:11:09
【问题描述】:

我正在尝试创建一个汇总列(column4),如果 column1、column2 不为 null 并且 column3 为 null,则它将包含 column1、column2 的总值。这个理论很简单,但我就是不能让它发挥作用。

我已搜索堆栈,但找不到专门解决此问题的答案。

UPDATE table1
SET "column4" = "column1" + "column2"
WHERE "column1" AND "column2" IS NOT NULL 
AND "column3" IS NULL;

错误:AND 的参数必须是布尔类型,而不是数字类型
第 4 行:在哪里“column1”和“column2...

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    您必须为列单独重复IS NOT NULL 断言:

    UPDATE table1
    SET column4 = column1 + column2
    WHERE column1 IS NOT NULL AND column2 IS NOT NULL AND column3 IS NULL;
    

    您可以通过认识到为了使column1column2 都不是NULL,这两个列的总和也必须不是NULL,来尝试缩短上述内容:

    UPDATE table1
    SET column4 = column1 + column2
    WHERE (column1 + column2) IS NOT NULL AND column3 IS NULL;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 2023-01-13
      • 1970-01-01
      • 2019-02-04
      • 2021-10-07
      • 1970-01-01
      相关资源
      最近更新 更多