用数字1-1000填充Postgres数据库吗? [英] Populate Postgres database with numbers 1-1000?

查看:87
本文介绍了用数字1-1000填充Postgres数据库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pgAdmin3的新手,我想用数字1-1000填充pgAdmin3中的数据库.我该怎么做呢?当前,我已经创建了一个名为MyDatabase的数据库(其中没有任何内容).每行应对应其数值(第1行应包含1,第2行应包含2,依此类推...)

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

推荐答案

您没有填充数据库"-您填充了:

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

使用generate_series()

假设您有一个名为my_table的表,其中有一个名为id的列,则可以执行以下操作:

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

这篇关于用数字1-1000填充Postgres数据库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆