how to execute pgsql script in pgAdmin?

試著忘記壹切 提交于 2019-12-21 03:35:23

问题


I want to execute some pgScript directly from the pgAdmin editor UI.

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.


回答1:


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

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



回答2:


There is no PRINT command. Use raise notice instead.

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



来源:https://stackoverflow.com/questions/26117622/how-to-execute-pgsql-script-in-pgadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!