COMMIT within a PostgreSQL function fails

30 views Asked by At

I would like to generate test data this way:

create table test.persons (
id serial primary key,
first_name varchar,
last_name varchar
);

create or replace function test.generate_persons() returns void as $$
begin 
for x in 1..10 loop
    for y in 1..10 loop
        insert into test.persons (first_name, last_name) values (
            'max',
            'meier'
        );  
    end loop;
    commit;
end loop;
end;
$$ language plpgsql;

select test.generate_persons()

But get the error "invalid transaction termination". Why?

0

There are 0 answers