David S.
David S.

Reputation: 11200

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.

Upvotes: 17

Views: 31681

Answers (2)

Vivek S.
Vivek S.

Reputation: 21963

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

Upvotes: 33

Clodoaldo Neto
Clodoaldo Neto

Reputation: 125534

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

Upvotes: 4

Related Questions