将数据从CSV文件导入PG数据库

    xiaoxiao2021-03-25  130

    csv文件内容: [postgres@pg ~]$ vi PGOracle.csv 1,2,3 4,5,6 7,8,9 创建了新表: postgres=# create table testim(col1 text,col2 text,col3 text); CREATE TABLE 从文件导入数据: postgres=# copy testim from '/home/postgres/PGOracle.csv' CSV HEADER; COPY 2 查看导入数据: postgres=# select * from testim; col1 | col2 | col3 ------+------+------ 4 | 5 | 6 7 | 8 | 9 (2 rows) postgres=# 发现少了第一行,这是可预料的结果,因为指定了 CSV HEADER,此命令会忽略第一行。 但是发现去掉CSV HEADER会报错: postgres=# copy  testim from '/home/postgres/PGOracle.csv' ; ERROR:  missing data for column "col2" CONTEXT:  COPY testim, line 1: "1,2,3" 那么以后做CSV导入的时候就要注意一下了。
    转载请注明原文地址: https://ju.6miu.com/read-13112.html

    最新回复(0)