Search code examples
sqlpostgresqlplpgsql

How to execute a query multiple times in PostgreSQL


What is the PostgreSQL equivalent to the TSQL “go” statement?

I have a query to insert a record into a table

--something like this

Insert into employee values(1,'Mike');
GO n;

I want this query to be executed n number of times.


Solution

  • try using loop:

    do
    $$
    declare 
      i record;
    begin
      for i in 1..3 loop
        Insert into employee values(1,'Mike');
      end loop;
    end;
    $$
    ;