How can I generate big data sample for Postgresql using generate_series and random?

abelard2008

I want to generate big data sample (almost 1 million records) for studying tuplesort.c's polyphase merge in postgresql, and I hope the schema as follows:

CREATE TABLE Departments (code VARCHAR(4), UNIQUE (code));
CREATE TABLE Towns (
  id SERIAL UNIQUE NOT NULL,
  code VARCHAR(10) NOT NULL, -- not unique
  article TEXT,
  name TEXT NOT NULL, -- not unique
  department VARCHAR(4) NOT NULL REFERENCES Departments (code),
  UNIQUE (code, department)
);

how to use generate_series and random for do it? thanks a lot!

Clodoaldo Neto

To insert one million rows into Towns

insert into towns (
    code, article, name, department
)
select
    left(md5(i::text), 10),
    md5(random()::text),
    md5(random()::text),
    left(md5(random()::text), 4)
from generate_series(1, 1000000) s(i)

Since id is a serial it is not necessary to include it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I generate random sample data in my Oracle database?

PostgreSQL - GENERATE_SERIES issue - simulating data

Using generate_series in PostgreSQL query

How to add result of generate_series to array in PostgreSQL?

How can I generate random variables according to data types?

How can I generate a random int using the "crypto/rand" package?

How can I generate random code using SuiteScript

How can i generate a formatted random string using ReactJS

How can I generate a random hex color code using python?

How would I generate a random data series in Python with events?

Generate random sample using weights by group

How can I generate random alphanumeric strings?

How can I generate random shades of an RGB?

How can I generate random items with conditions?

How can I get the "shape" of some data so I can generate similar random numbers in numpy/scipy

How can I generate a random image using random function for infinite time?

How can i generate random variables using np.random.zipf for a given range of values?

PostgreSQL: replace generate_series with an array

PostgreSQL generate_series with WHERE clause

Postgresql generate_series dynamic interval

PostgreSQL Generate_Series() Insert Not Completing

generate_series() postgresql equivalent in cassandra

How to generate xml file with an existing dtd for sample of data using Java

How to generate random unique number in PostgreSQL using function

R-How to generate random sample of a discrete random variables?

Using generate_series with Rails ActiveRecord

Delete range of rows using generate_series()?

Using OVER function with generate_series

How can i use Faker.js to generate random data for protractor test cases.?