我想直接从pgAdmin编辑器界面执行一些pgScript。
FOR i IN 1..10 LOOP
PRINT i; -- i will take on the values 1,2,3,4,5,6,7,8,9,10 within the loop
END LOOP;
但我总是得到
[ERROR ] 1.0: syntax error, unexpected character
我也尝试使用do$$...$$来包装代码,但并没有解决问题。
我想直接从pgAdmin编辑器界面执行一些pgScript。
FOR i IN 1..10 LOOP
PRINT i; -- i will take on the values 1,2,3,4,5,6,7,8,9,10 within the loop
END LOOP;
但我总是得到
[ERROR ] 1.0: syntax error, unexpected character
我也尝试使用do$$...$$来包装代码,但并没有解决问题。
除了Clodoaldo Neto的回答之外,您也可以尝试这个。
DO
$$
BEGIN
FOR i IN 1..10 LOOP
RAISE NOTICE '%', i; -- i will take on the values 1,2,3,4,5,6,7,8,9,10 within the loop
END LOOP;
END
$$
没有 PRINT
命令。请使用 raise notice
代替。
create function f()
returns void as $$
begin
FOR i IN 1..10 LOOP
raise notice '%', i; -- i will take on the values 1,2,3,4,5,6,7,8,9,10 within the loop
END LOOP;
end;
$$ language plpgsql;
DO
块,不能直接编写 PL/PgSQL。 - Craig Ringer