这是我简单的匿名代码块:
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
^
答案 0 :(得分:60)
自己解决了,meh:
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;
$$;