【发布时间】:2016-11-12 04:05:43
【问题描述】:
我有一个包含 4000 列的 CSV 文件,我需要将它导入到 postgres 数据库。我正在使用 pgadminIII。在 ORACLE SQL 中,有一个选项,我可以右键单击表并导入。 Postgres中有没有类似的方法。如果不是,那么创建包含这么多列的表的最有效方法是什么?
更新 - 我得到了它的工作:
import pandas as pd
df = pd.read_csv('C:/Users/dbharali0376/Desktop/Merge_N_Reorder/ip_merged_52_final.csv',dtype='unicode')
df.columns = [c.lower() for c in df.columns]
from sqlalchemy import create_engine
engine = create_engine('postgresql://postgres:password@localhost:5432/postgres')
df.to_sql("trial", engine, if_exists='append',index=False)
这会根据输入的 csv 创建一个新表。
【问题讨论】:
-
你确定你可以用 Oracle 做吗?我记得,每个表限制有 1000 列。但是,PostgreSQL 也不是那么“橡皮”,并且有Maximum Columns per Table 250 - 1600 depending on column types 的限制。
-
@Gordon Linoff,对于 COPY,我已经需要一个表才能存在。有没有办法通过 GUI 创建一个包含这么多列的表,或者我必须输入每个列的名称。
-
没有办法,因为列太多了。
标签: postgresql postgresql-9.1 postgresql-9.2