1、数据导入 - COPY FROM
CREATE DATABASE c04_datacleaning;
c c04_datacleaning
创建新的数据库
COPY table_name [ ( column_name [, ...] ) ]
FROM { 'filename' | PROGRAM 'command' | STDIN }
[ [ WITH ] ( option [, ...] ) ]
COPY FROM语法
CREATE TABLE data(
房屋编码 int,
小区 text,
朝向 text,
房屋单价 numeric,
参考首付 numeric,
参考总价 numeric,
经度 numeric,
纬度 numeric
);
创建表格data
注意,需要创建和源数据一致的表头名称及数据类型
COPY data FROM 'C:UsersiHJX_AlienwareDesktop深圳罗湖二手房信息.csv' WITH CSV HEADER ENCODING 'utf8';
导入数据,这里是用COPY → 从客户端寻找文件复制
①excel/txt等先导出csv; ②设置编码utf-8;③导入数据
注意路径不能太复杂
WITH CSV HEADER → 表头信息
ENCODING → 设置编码
COPY是从服务端寻找文件,COPY是从客户端上寻找文件
2、数据导出 - COPY TO
COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
TO { 'filename' | PROGRAM 'command' | STDOUT }
[ [ WITH ] ( option [, ...] ) ]
COPY TO语法
COPY data TO 'C:UsersiHJX_AlienwareDesktop数据导出.csv' WITH CSV HEADER;
导出数据,这里是用COPY → 导出客户端数据