如何动态选择查询

时间:2016-09-22 05:19:39

标签: sql postgresql postgresql-9.4

update table1 set column2 = max_value + sum;
  

获取错误:错误:运算符不存在:字符变化=   整数。

此外,当我尝试运行以下代码时:

{
"error": {
    "errors": [
        {
            "domain": "global",
            "reason": "notFound",
            "message": "Not Found"
        }
       ],
    "code": 404,
    "message": "Not Found"
    }
}

我收到另一个错误:

  

“错误:列”max_value“不存在”

1 个答案:

答案 0 :(得分:0)

您可以使用:

CREATE OR REPLACE FUNCTION maxvaloftable ()
 RETURNS integer AS
$BODY$

   DECLARE

resultat integer = 2;

BEGIN

resultat= (SELECT MAX(sum) FROM  table) ;

RETURN resultat;
END;
$BODY$
 LANGUAGE plpgsql VOLATILE STRICT
    COST 100;
ALTER FUNCTION maxvaloftable()
 OWNER TO postgres;

update table1 set column2 = (select  maxvaloftable ()) + sum;