【发布时间】:2020-09-18 19:26:15
【问题描述】:
我有两个 sql(postgres) 表,我需要将一列从一个表插入到另一个表。 请注意,每个表包含大约 1 亿条记录
例如我的表模式:
first_table:
id int, first_column int, second_column int, third_column;
second_table:
id int, fourth_column int;
注意两个表中的 id 列都是主键。
我需要得到下表:
first_table:
id int, first_column int, second_column int, third_column int, fourth_column int;
简而言之,我需要根据 id(primary key) 列合并这两个表。
我试过了:
- 为 first_table 添加一个名为 Fourth_column 的空列,并对其进行更新。
UPDATE first_column AS f
SET fourth_column = t.fourth_column
FROM second_table AS t
WHERE f.id = t.id;
此方法可行,但每个sql表包含大约1亿条记录,并且此解决方案需要大量时间(对我的程序来说是关键时间)。
- 使用某些类型的 postgres 连接,但文档中的示例令我失望。
是否存在某种方法或规则可以在短时间内进行此更新/传输。也许我应该使用一些高级的大数据库,比如 SparkSQL 或其他的。
问候, qwew
【问题讨论】:
-
当你需要
fourth_column时,你为什么不离开桌子去加入? -
@MikeOrganek 我不知道该怎么做。我在 postgres 文档中找不到方法。
标签: sql postgresql bigdata