HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMajor

How to insert 10000 new rows?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
rowsinsertnew10000how

Problem

Presumably there is a straight forward and easy solution. I'm wanting to create 10000 new rows - that are numbered sequentially with no data per row (except sequentially numbered id).
I have used:
INSERT INTO bins (id)
VALUES (1)


to create a single row with id '1'

How do I create 10000 rows with corresponding id number?

Version: PostgreSQL 9.5.5

Solution

You can use the generate_series() set returning function:

INSERT INTO bins (id) 
SELECT g.id
FROM generate_series(1, 10000) AS g (id) ;

Code Snippets

INSERT INTO bins (id) 
SELECT g.id
FROM generate_series(1, 10000) AS g (id) ;

Context

StackExchange Database Administrators Q#189599, answer score: 26

Revisions (0)

No revisions yet.