How To Create A Postgres Table With Million Rows?
There are many scenarios where you need a lot of data created very quickly. So, let's see an example of how to create a table in Postgres with a million rows.
Note: You need to have Docker already installed on your laptop.
Step 1: Pull Docker image
docker pull postgres
Step 2: Run Docker Container
docker run -e POSTGRESS_PASSWORD=postgres --name pg1 postgress
pg1 -> name of the container
postgres -> name of the image
Step 3: Log into the container Go to a new terminal and type the following command to log into the container pg1
docker exect -it pg1 psql -U postgres
This will take you to the psql terminal
Step 4: Create Table
create table temp(t int);
We are just creating a table with one int column.
Step 5: Run SQL query to create a million rows
insert into temp select from generate_series(0,1000000);
Note: generate_series is a Postgresql function,
That's it! There you have a table with a million rows.