如何在pgAdmin中执行pgsql脚本?

时间:2014-09-30 09:42:31

标签: postgresql plpgsql pgadmin

我想直接从 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;

但我总是得到

[ERROR    ] 1.0: syntax error, unexpected character

我还试图用 do $$ ... $$ 包装代码,但是没有解决问题。

2 个答案:

答案 0 :(得分:21)

除了Clodoaldo Neto's Answer。你也可以尝试这个

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

答案 1 :(得分:3)

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