create writable external table ext_w_test001(
id bigint,
name varchar(128)
)
location('gpfdist://10.0.0.6:8888/gpextdata/test001.txt')
format 'csv'
encoding 'GB18030';
可写测试
insert into ext_w_test001 select generate_series(1,1000,1),1;
# 插入数据后登陆服务器10.0.0.6(文件服务器)执行下列shell指令
wc -l /home/gpadmin/gpextdata/test001.txt
建立可读gpfdist外部表
create readable external table ext_r_test001(
id bigint,
name varchar(128)
)
location('gpfdist://10.0.0.6:8888/gpextdata/test001.txt')
format 'csv'
encoding 'GB18030'
log errors into err_r_test001
segment reject limit 10 rows;
可读测试
select count(*) from ext_r_test001;
select * from ext_r_test001 limit 5;
删除gpfdist外部表
找出对应的外部表和err表
方案一
External table "public.ext_w_test001"
Column | Type | Modifiers
--------+------------------------+-----------
id | bigint |
name | character varying(128) |
Type: writable
Encoding: GB18030
Format type: csv
Format options: delimiter ',' null '' escape '"' quote '"'
External location: gpfdist://10.0.0.6:8888/gpextdata/test001.txt
Distributed randomly
dw=# \d ext_r_test001
External table "public.ext_r_test001"
Column | Type | Modifiers
--------+------------------------+-----------
id | bigint |
name | character varying(128) |
Type: readable
Encoding: GB18030
Format type: csv
Format options: delimiter ',' null '' escape '"' quote '"'
External location: gpfdist://10.0.0.6:8888/gpextdata/test001.txt
Segment reject limit: 10 rows
Error table: err_r_test001
方案二
SELECT x.location,
x.fmttype,
x.fmtopts,
x.command,
x.rejectlimit,
x.rejectlimittype,
x.writable,
(SELECT relname
FROM pg_class WHERE Oid=x.fmterrtbl) AS errtblname,
pg_catalog.pg_encoding_to_char(x.encoding
),
x.fmterrtbl = x.reloid AS errortofile
FROM pg_catalog.pg_exttable x,
pg_catalog.pg_class c
WHERE x.reloid = c.oid
AND c.oid = 'public.ext_r_test001'::regclass;
删除外部表(删除之前查看建表语法有没有错误表存在)
drop table err_r_test001;
drop external table public.ext_r_test001;
drop external table public.ext_w_test001;
create writable external web table ext_w_cmd_web(
id bigint,
name varchar(128)
)
execute '/home/gpadmin/unload.sh' on 3
format 'csv'
encoding 'GB18030';
create readable external web table ext_r_cmd_web(
id bigint,
name varchar(128)
)
execute '/home/gpadmin/load.sh' on 3
format 'csv'
encoding 'GB18030'
log errors into err_r_cmd_tab
segment reject limit 10 rows;
可读测试
select count(*) from ext_r_cmd_web;
select * from ext_r_cmd_web;
建立hdfs外部表
建立可写hdfs外部表
CREATE writable EXTERNAL TABLE ext_w_hdfs_test
(id int, name text, sponsor text)
LOCATION ('hdfs://oushu/hawq/default_filespace/test' ) FORMAT 'CSV'
encoding 'GB18030';
可写测试
insert into ext_w_hdfs_test select 1,2,3;
建立可读hdfs外部表
CREATE readable EXTERNAL TABLE ext_r_hdfs_test
(id int, name text, sponsor text)
LOCATION ('hdfs://oushu/hawq/default_filespace/test' ) FORMAT 'CSV'
encoding 'GB18030'
log errors into err_r_hdfs_tab
segment reject limit 10 rows;
可读测试
select count(*) from ext_r_hdfs_test;
select * from ext_r_hdfs_test;