码迷,mamicode.com
首页 > Web开发 > 详细

Netezza external table example

时间:2015-10-29 21:55:36      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:

--External table is used to import/export flat file to Netezza system,
--since Netezza host is a Linux box, the import/export file format could only be linux format(use LF as row delimiter).

--several Key configuration
ENCODING ‘UTF8‘-- default is INTERNAL, which is for ansi file
SKIPROWS 1 -- SKIP ROW IS SET TO 1 IF THE FILE HAS A HEADER ROW.
FORMAT ‘FIXED‘ --default is text, which means the delimited format
DELIMITER ‘,‘ --default is pipe, could only set one character
ESCAPECHAR ‘/‘ --if the file is delimited, and some fields have the delimiter in it, we could use the setting
QUOTEDVALUE double --default is no quotedvalue
LOGDIR ‘/mnt/hqaasan01/development_adhoc/‘ --specify the log dir, the log is very helpful when troubleshooting
;
----------------------------------------------------------------
--Input case

--Fetch data from files using a transient external table(TET)
SELECT * FROM EXTERNAL ‘/mnt/hqaasan01/development_adhoc/Test.txt‘
(    id int,
     name varchar(50)
)
USING
(
    --options
);

INSERT INTO <TABLE_NAME>
SELECT * FROM EXTERNAL ‘/mnt/hqaasan01/development_adhoc/AARP_1968_ASI_Adhoc_Transaction/Test.txt‘
(    id int,
     name varchar(50)
)
USING
(
    --options
);

CREATE <TABLE_NAME> AS
SELECT * FROM EXTERNAL ‘/mnt/hqaasan01/development_adhoc/AARP_1968_ASI_Adhoc_Transaction/Test.txt‘
(    id int,
     name varchar(50)
)
USING
(
    --options
);

----------------------------------------------------------------
--Create external table from files, the external tables could be used later
--DROP TABLE DW_External_Test;
CREATE EXTERNAL TABLE DW_External_Test
(
    F1 NVARCHAR(50)
)
USING
(
DATAOBJECT(‘/mnt/hqaasan01/development_adhoc/ansi.txt‘)
ENCODING ‘INTERNAL‘
);

SELECT * FROM AD_HOC..DW_External_Test LIMIT 100;

--Note: it is not allowed to add data to External table
INSERT INTO DW_External_Test VALUES (‘VAWANG‘);

--External table with FIXED FORMAT

CREATE EXTERNAL TABLE STAGE_ASI..ASI_REGAL_NORWEGIAN_20150209_EXTERNAL
(
RecordType VARCHAR(2),
CHID BIGINT,
tDate VARCHAR(10),
)
USING
(
DATAOBJECT(‘/mnt/hqaasan01/development_adhoc/test.txt‘)
FORMAT ‘FIXED‘
LOGDIR ‘/tmp/test.txt‘
LAYOUT
    (
BYTES 2,
BYTES 19,
BYTES 10
    )
);

DROP TABLE Test_Fixed;
CREATE EXTERNAL TABLE Test_Fixed
(
F1 CHAR(2),
F2 CHAR(2)
)
USING
(
DATAOBJECT(‘/mnt/hqaasan01/development_adhoc/test.txt‘)
LOGDIR ‘/tmp/test.txt‘
FORMAT ‘FIXED‘
LAYOUT
    (
bytes 2,
bytes 2
    )
);

SELECT * FROM Test_Fixed;


-----------------------------------------
--Output internal tables to external file
CREATE EXTERNAL TABLE DW_EX2 ‘/mnt/hqaasan01/development_adhoc/AARP_1968_ASI_Adhoc_Transaction/NZOUPUT.txt‘
using (DELIM ‘,‘)
AS
SELECT * from DW_TEST
;
 
insert into DW_ex2 VALUES (1,‘VAWANG‘);
--------------------------------------------

Netezza external table example

标签:

原文地址:http://www.cnblogs.com/davablog/p/4921835.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!