ERROR: "coalesce" is not a known variable in INTO clause

ERROR: "coalesce" is not a known variable in INTO clause

以下是我的示例函数

create or replace function samp(in a int) returns int as
$$
declare 
val int;
val1 int;
begin
select coalesce(a-1,1) into val,coalesce(a-2,1) into val1;
return val + val1;
end;
$$
language plpgsql 

执行时出现以下错误

ERROR: "coalesce" is not a known variable LINE 7: select coalesce(a-1,1) into val,coalesce(a-2,1) into val1;

您的语法错误 - into 是适用于所有变量的单个子句,而不是应用于每个变量的关键字:

SELECT coalesce(a-1,1), coalesce(a-2,1)
INTO   val, val1;