用COPY命令从csv文件中导入数据

简介:

开始

csv 文件的内容:

id    name    departno    age
1    gao    10    30
2    jian    11    35
3    tom    11    30

导入前:

复制代码
postgres=# select a.relpages, a.reltuples, a.relfilenode,a.reltype,b.typname from pg_class a, pg_type b where a.relname like 'gaotab%' and a.reltype=b.oid;
 relpages | reltuples | relfilenode | reltype | typname 
----------+-----------+-------------+---------+---------
(0 rows)

postgres=# 
复制代码

导入之前,必须要建立好表的结构

复制代码
postgres=# create table gaotab(id integer,name varchar(20),departno integer,age integer);
CREATE TABLE
postgres=# 
postgres=# 
postgres=# COPY gaotab from '/soft/test.csv' with csv header;COPY 3
postgres=# select * from gaotab;
 id | name | departno | age 
----+------+----------+-----
  1 | gao  |       10 |  30
  2 | jian |       11 |  35
  3 | tom  |       11 |  30
(3 rows)

postgres=# 
复制代码

导入已经成功

导入后再看:

复制代码
postgres=# select a.relpages, a.reltuples, a.relfilenode,a.reltype,b.typname from pg_class a, pg_type b where a.relname like 'gaotab%' and a.reltype=b.oid;
 relpages | reltuples | relfilenode | reltype | typname 
----------+-----------+-------------+---------+---------
        0 |         0 |       16384 |   16386 | gaotab
(1 row)

postgres=# 



postgres=# analyze gaotab;
ANALYZE
postgres=# select a.relpages, a.reltuples, a.relfilenode,a.reltype,b.typname from pg_class a, pg_type b where a.relname like 'gaotab%' and a.reltype=b.oid;
 relpages | reltuples | relfilenode | reltype | typname 
----------+-----------+-------------+---------+---------
        1 |         3 |       16384 |   16386 | gaotab
(1 row)

postgres=# 
复制代码




目录
相关文章
|
7月前
|
数据库
psc文件文件如何导入数据库
psc文件文件如何导入数据库
107 0
|
10月前
|
Python
python 读取 .csv/.xlsx/.xls 文件数据—批量修改文件名
python 读取 .csv/.xlsx/.xls 文件数据—批量修改文件名
|
10月前
|
数据处理
R|批量循环处理同一格式文件-csv,txt,excel
R|批量循环处理同一格式文件-csv,txt,excel
|
10月前
|
测试技术 数据安全/隐私保护
|
存储 数据挖掘 数据库
|
关系型数据库 数据库 PostgreSQL
导出CSV文件
导出CSV文件
332 0
|
关系型数据库 MySQL 数据库
读取txt写入csv,读取csv写入mysql
用Python实现读取txt写入csv,读取csv写入mysql
251 0
读取txt写入csv,读取csv写入mysql
|
SQL Shell 数据库
利用groovy把表中数据导出成txt或csv
胶水语言就是胶水,写起也挺快的.这个脚本主要是从数据库中把表中的数据导出来生成文件.而不用每次都打开数据库编辑器去手工收集.
1075 0
|
JSON 数据格式 索引
深入理解pandas读取excel,txt,csv文件等命令
深入理解pandas读取excel,txt,csv文件等命令 pandas读取文件官方提供的文档 在使用pandas读取文件之前,必备的内容,必然属于官方文档,官方文档查阅地址 http://pandas.
6755 0
|
Python Windows