postgresql 如何在 pgAdmin 中执行 pgsql 脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26117622/
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-09 05:47:38  来源:igfitidea点击:

how to execute pgsql script in pgAdmin?

postgresqlplpgsqlpgadmin

提问by David S.

I want to execute some pgScriptdirectly from the pgAdmineditor UI.

我想直接从pgAdmin编辑器 UI执行一些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;

But I always got

但我总是得到

[ERROR    ] 1.0: syntax error, unexpected character

I also tried to wrap the code with do$$...$$, but does not solve the problem.

我也尝试用do$$...$$包装代码,但没有解决问题。

回答by Vivek S.

apart from Clodoaldo Neto's Answer.You can try this also

除了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
$$

回答by Clodoaldo Neto

There is no PRINTcommand. Use raise noticeinstead.

没有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;

http://www.postgresql.org/docs/current/static/plpgsql.html

http://www.postgresql.org/docs/current/static/plpgsql.html