我需要创建包含 1000 列和 1M 行的随机数据表。
我知道用于在具有某些列的表中插入 1M 行的脚本:
INSERT INTO foo
SELECT md5(random()::text), md5(random()::text), ..., md5(random()::text)
FROM generate_series(1, 1000000) AS i;
但我不知道:
- 如何通过脚本创建具有 1000 个列(名称:c1、c2、c3、...、c999、c1000)的表(需要 SQL 脚本)
- 如何使用
md5(random()::text)
的结果为行的每个字段插入 1M 行(需要 SQL 脚本) - 是否可以创建具有 1M 列的表?或者 PostgeSql 有 1200 列的限制?也许我可以更改此限制?
最佳答案
How to create table with 1000 of colums (names: c1, c2, c3, ... , c999, c1000) by script (need the SQL script):
CREATE TABLE t AS
WITH cte AS (
VALUES (
'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
,'','','','','','','','','','','','','','','','','','','','','','','','',''
)
)
SELECT *
FROM cte
WHERE 1=2;
Is it possible to create table with 1M of colums? Or PostgeSql has limit of 1200 colums? Maybe I can change this limit?
我不这么认为。基于doc
Maximum Columns per Table 250 - 1600 depending on column types
关于sql - PostgreSql:用于创建具有 1000 列的表的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47398869/