Search code examples
postgresqlplpgsqlpgadmin

how to execute pgsql script in pgAdmin?


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.


Solution

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