postgresql - psql - loop variable of loop over rows must be a record or row variable or list of scalar variables
标签 stackoverflow.com/questions
这是我的简单匿名代码块:
do $$
declare foo varchar(50) := '';
begin
for a in
select a from (values('foo'), ('bar'), ('fooBar')) s(a)
loop
foo := a;
print foo;
end loop;
end;
$$;
当我运行它时:
psql -f test.sql
我收到此错误:
psql:test.sql:11: ERROR: loop variable of loop over rows must be a record or row variable or list of scalar variables
LINE 4: for a in
^
最佳答案
自己解决了,呵呵。需要申报arow record
.
do $$
declare
arow record;
foo varchar(50);
begin
for arow in
select a from (values('foo'), ('bar'), ('fooBar')) s(a)
loop
foo := arow.a;
RAISE NOTICE 'Calling cs_create_job(%)', foo;
end loop;
end;
$$;
转载自:postgresql - psql - 在行上循环的循环变量必须是记录或行变量或标量变量列表 - IT工具网 (coder.work)