Can someone spot if I'm doing something wrong here...
# sql
l
Can someone spot if I'm doing something wrong here? I'm trying to go through all the rows in my table and insert data to a different table. Inserting outside the loop works fine, however nothing happens here even though the functions results in success.
Copy code
create or replace function public.add_region_ranks() 
returns void
as $$
declare
  player record;
begin
  for player in select * from profiles
  loop
    insert into profiles_ratings (profile_id, region_id, game_mode_id) values (player.id, 1, 1);
  end loop;
end;
$$ language plpgsql security definer;
For the record,
profile_id
,
region_id
, and
game_mode_id
all have foreign key relations to other tables
Facepalm, rubberducked this with a friend and realized that I'm not calling the function anywhere, just creating it 😂
Case closed
s
This form is more idiomatic to SQL(it might be a bit faster too, since the function can just use 'language sql')
Copy code
sql
insert into profiles_ratings (profile_id, region_id, 
game_mode_id)
select player.id, 1, 1 from profiles;