sql - PostgreSql:用于创建具有 1000 列的表的脚本

标签 sql postgresql

我需要创建包含 1000 列和 1M 行的随机数据表。

我知道用于在具有某些列的表中插入 1M 行的脚本:

INSERT INTO foo
   SELECT md5(random()::text), md5(random()::text), ..., md5(random()::text)
   FROM generate_series(1, 1000000) AS i;

但我不知道:

  1. 如何通过脚本创建具有 1000 个列(名称:c1、c2、c3、...、c999、c1000)的表(需要 SQL 脚本)
  2. 如何使用 md5(random()::text) 的结果为行的每个字段插入 1M 行(需要 SQL 脚本)
  3. 是否可以创建具有 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;

DBFiddle Demo

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/

相关文章:

php - 将 mysql 结果(大关联数组)转换为嵌套数组

mysql - 如何在mysql表中选择当月的日期范围?

ruby-on-rails - 使用 heroku db :push when I'm using PostgreSQL as development db 获取 SQLite 错误

sql - 触发器-postgres

java - 无法 Autowiring 。找不到 ... 类型的 bean

mysql - 在 WHERE 子句中使用 FULLTEXT 搜索的相关性得分

php - MySQL:每个日期的组事件

sql - 如何从Oracle中的正则表达式中提取组?

postgresql - Postgres : check if array field contains value?

sql - 使用CTE在SQL中生成测试数据