如何使用 generate_series 和 random 为 Postgresql 生成大数据样本? [英] How can I generate big data sample for Postgresql using generate_series and random?
本文介绍了如何使用 generate_series 和 random 为 Postgresql 生成大数据样本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想生成大数据样本(近100万条记录)用于研究tuplesort.c在postgresql中的多相合并,希望schema如下:
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)
);
如何使用 generate_series 和 random 来实现?非常感谢!
how to use generate_series and random for do it? thanks a lot!
推荐答案
向 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)
因为 id
是一个 serial
,所以没有必要包含它.
Since id
is a serial
it is not necessary to include it.
这篇关于如何使用 generate_series 和 random 为 Postgresql 生成大数据样本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文