Populate Postgres database with numbers 1-1000?

橙三吉。 提交于 2020-01-05 04:22:12

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/44786031/populate-postgres-database-with-numbers-1-1000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!