how to execute pgsql script in pgAdmin?

David S. picture David S. · Sep 30, 2014 · Viewed 22.1k times · Source

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.

Answer

Vivek S. picture Vivek S. · Sep 30, 2014

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