Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate Postgres database with numbers 1-1000?

I'm a newbie at pgAdmin3 and I want to populate a database in pgAdmin3 with numbers 1-1000. How can I go about doing this? Currently, I have a database created called MyDatabase (with nothing in it). Every row should correspond to its numerical value (row 1 should contain 1, row 2 should contain 2, etc...)

like image 700
ninchicken Avatar asked Oct 31 '25 15:10

ninchicken


1 Answers

You don't populate a "database" - you populate a table:

This can be done quite easily using generate_series()

Assuming you have a table called my_table with a column named id you can do:

insert into my_table (id)
select i
from generate_series(1,1000) i