外部表定义
--2014-03-04 13:51:30-- http://mirrors.aliyun.com/repo/Centos-6.repo
正在解析主机 mirrors.aliyun.com... 115.28.122.210, 112.124.140.210
正在连接 mirrors.aliyun.com|115.28.122.210|:80... 已连接。
可读外部表(不可以做dml操作)
可写外部表(只insert,不可以select,update,delete)
装载
创建外部表
=# CREATE EXTERNAL WEB TABLE ext_expenses (name text,
date date, amount float4, category text, description text)
LOCATION ( 'http://intranet.company.com/expenses/sales/file.csv',
'http://intranet.company.com/expenses/exec/file.csv',
'http://intranet.company.com/expenses/finance/file.csv',
'http://intranet.company.com/expenses/ops/file.csv',
'http://intranet.company.com/expenses/marketing/file.csv',
'http://intranet.company.com/expenses/eng/file.csv' )
FORMAT 'CSV' ( HEADER );
date date, amount float4, category text, description text)
LOCATION ( 'http://intranet.company.com/expenses/sales/file.csv',
'http://intranet.company.com/expenses/exec/file.csv',
'http://intranet.company.com/expenses/finance/file.csv',
'http://intranet.company.com/expenses/ops/file.csv',
'http://intranet.company.com/expenses/marketing/file.csv',
'http://intranet.company.com/expenses/eng/file.csv' )
FORMAT 'CSV' ( HEADER );
装载外部表数据
=# INSERT INTO expenses_travel
SELECT * from ext_expenses where category='travel';
或者想要快速装载全部数据到一个新的数据库表中:
=# CREATE TABLE expenses AS SELECT * from ext_expenses;
SELECT * from ext_expenses where category='travel';
或者想要快速装载全部数据到一个新的数据库表中:
=# CREATE TABLE expenses AS SELECT * from ext_expenses;
测试:
[root@mdw ~]# wget http://mirrors.aliyun.com/repo/Centos-6.repo
--2014-03-04 13:51:30-- http://mirrors.aliyun.com/repo/Centos-6.repo
正在解析主机 mirrors.aliyun.com... 115.28.122.210, 112.124.140.210
正在连接 mirrors.aliyun.com|115.28.122.210|:80... 已连接。