4

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...)

ninchicken
  • 99
  • 1
  • 8

1 Answers1

12

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
Nick
  • 7,103
  • 2
  • 21
  • 43
  • Where does that get typed into on the program (pgAdmin)? – ninchicken Jun 27 '17 at 18:35
  • 1
    @ninchicken in the query window. Click the icon that looks like a magnifying glass with "SQL" in it, then press the green "play" icon to execute your query – Neil McGuigan Jun 27 '17 at 18:47
  • Thanks. I've highlighted my table with one column called "id". However, I type in those commands and I get an error saying the table does not exist. – ninchicken Jun 27 '17 at 19:28
  • If you just want a single-column table with the series of 1-1000, add a "CREATE TABLE my_table AS " in front of the answer listed above. That'll create the table and populate it with the results of the select statement. – R Scott Jun 28 '17 at 00:12