如何在postgres sql中分配变量


DECLARE 
eno integer := 0;
emp string ;
select into eno emp_no from "public"."salaries" GROUP BY emp_no ORDER BY max(salary) DESC LIMIT 1;
-- gives the emp_no of the employee with maximim salary
select INTO emp CONCAT(first_name, ' ' , last_name) as "Name" from "employees" 
WHERE emp_no = eno;
-- gives the name of the employee with the emp_no from preveous result 
raise NOTICE "The Employe with maximum salary is %",emp;

错误信息:Error:在"整数"处或附近有语法错误

我试图获得最高工资的emp名称请帮助

你需要把你的声明和你的值的初始化分开。

这样做:

DECLARE 
eno integer;
BEGIN
eno := 0;
... rest of your code here
END;