如何改进数据导入方法?

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
罗非鱼
帖子: 980
注册时间: 2008-04-12 12:44

如何改进数据导入方法?

#1

帖子 罗非鱼 » 2008-12-15 17:01

系统环境
ubuntu8.04+postgresql8.3
我的原始数据
/home/pt/test.csv
我的目的将/home/pt/test.csv导入postgresql数据库
我的做法
1、创建一个空白表
create table test1(open integer)
说明:用create语句,创建一个名为test1的数据表,字段open,数据类型为integer

2、导入数据
\copy test1(open) from '/home/pt/table.csv'

我的期望:
1、这个例子太简单,如果我的csv文件有N列,可否创建一个只有表名,没有任何字段的表,将csv文件文件导入数据库,原csv文件有多少列,就在导入时,自动产生多少列?
2、使用\copy test1(open) from '/home/pt/table.csv'语句时,csv文件必须全部是数据,没有字段,如果第一行是字段,第二行才有数据,我可否从第二行开始导入数据?
回复