Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 819
David S. Avatar asked Sep 30 '14 09:09

David S.


People also ask

How do I run a PostgreSQL script in pgAdmin?

Select the relevant portion and hit the F5 key in the SQL editor of pgAdmin. OR use the "Execute query" button (green arrow) in the toolbar. If nothing is selected, the whole script is executed.

How do I run a DB script in PostgreSQL?

Another easiest and most used way to run any SQL file in PostgreSQL is via its SQL shell. Open the SQL shell from the menu bar of Windows 10. Add your server name, database name where you want to import the file, the port number you are currently active on, PostgreSQL username, and password to start using SQL shell.

Does pgAdmin have psql?

Note: The PSQL tool is always available when pgAdmin is running in Desktop mode, but is disabled by default in Server mode. This is because users can run arbitrary shell commands through psql which may be considered a security risk in some deployments.


1 Answers

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
$$
like image 93
Vivek S. Avatar answered Oct 02 '22 12:10

Vivek S.