如何从CSV文件复制到PostgreSQL表与CSV文件中的标题? [英] How to copy from CSV file to PostgreSQL table with headers in CSV file?

查看:355
本文介绍了如何从CSV文件复制到PostgreSQL表与CSV文件中的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将CSV档案复制到Postgres表格。在这个表中有大约100列,所以如果我不需要重写它们。

I want to copy a CSV file to a Postgres table. There are about 100 columns in this table, so I do not want to rewrite them if I don't have to.

我使用 \copy table from'table.csv'delimiter','csv; 命令但没有创建表我获得错误:关系表不存在。如果我添加一个空表,我得到没有错误,但什么也没有发生。我尝试这个命令两三次,没有输出或消息,但是当我通过PGAdmin检查表时没有更新。

I am using the \copy table from 'table.csv' delimiter ',' csv; command but without a table created I get ERROR: relation "table" does not exist. If I add a blank table I get no error, but nothing happens. I tried this command two or three times and there was no output or messages, but the table was not updated when I checked it through PGAdmin.

有没有办法导入包含标题的表格,如我想做的那样?

Is there a way to import a table with headers included like I am trying to do?

推荐答案

这工作。第一行有列名。

This worked. The first row had column names in it.

COPY wheat FROM 'wheat_crop_data.csv' DELIMITER ';' CSV HEADER

这篇关于如何从CSV文件复制到PostgreSQL表与CSV文件中的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆