postgresql psql - 行循环的循环变量必须是记录或行变量或标量变量列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15949337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:08:28  来源:igfitidea点击:

psql - loop variable of loop over rows must be a record or row variable or list of scalar variables

postgresqlpsql

提问by Richard Knop

Here is my simple anonymous code block:

这是我的简单匿名代码块:

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;
$$;

When I run it:

当我运行它时:

psql -f test.sql

I get this error:

我收到此错误:

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
            ^

回答by Richard Knop

Solved it myself, 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;
$$;