在我的函数声明中:
$function$
declare
alllogins schema.EmployeeLogin;
nologins schema.Employee;
begin
SELECT * INTO alllogins FROM schema.EmployeeLogin;
SELECT * INTO nologins FROM schema.Employee AS a WHERE NOT EXISTS
(SELECT 1 FROM alllogins WHERE schema.EmployeeId = a.EmployeeId );
end;
$function$;
返回
ERROR: relation "alllogins" does not exist
LINE 1: ...ema.Employee AS a WHERE NOT EXISTS (SELECT 1 FROM alllogins ...
^
事实上存在,因为我已经SELECT * INTO
没有问题。为什么我可以SELECT INTO
而不是SELECT FROM
?
答案 0 :(得分:0)
您不能将PL / pgSQL变量用作表名。这与尝试将带有占位符的预准备语句用于表名称相同,但不支持。占位符和变量只能用于代替常量。
您必须使用EXECUTE
命令的动态SQL。