Netezza External Tables --How to use local files in external table
2014-03-05 17:23
591 查看
FROM: http://tennysusantobi.blogspot.com/2012/08/netezza-external-tables.html
Netezza External Tables
You can use Netezza's external table to view data from an external fileand use it like a database table. When you create an external table, the
actual data still sits in that physical external file, but you can
query it from Netezza like you can query a normal database table.
You can also use external tables to export data out of a Netezza table into a file.
From Netezza's Data Loading Manual - An external table allows Netezza
to treat an external file as a database table. An external table has a
definition (a table schema), but the actual data exists outside of the
Netezza appliance database. External tables can be used to access files
which are stored on the Netezza host server or, in the case of a remote
external table, Netezza can treat a file on a client system as an
external table (see REMOTESOURCE option).
Below are 2 examples to show you how to do both data export and "import".
I am using Aginity Workbench for Netezza on my windows machine (which
comes with a netezza odbc driver), and I have a text file stored in my
local drive C:\temp\testfile.txt which has the following column header
and 3 rows:
employeeid,employeename,salary
1,'John Lee',100000
2,'Marty Short', 120000
3,'Jane Mars', 150000
CREATE EXTERNAL TABLE ext_tbl_employees(
employee_id integer,
employee_name character varying(100),
salary decimal (10,2))
USING (
dataobject('c:\temp\testfile.txt')
remotesource 'odbc'
delimiter ','
skiprows 1);
Then in your Aginity workbench object browser, expand the folder
External Tables, and you will your new external table listed there.
You can then query the table just like a normal database table:
select *
from ext_tbl_employees
You can also create a transient external table, in which it only exists
for the duration of your query, which means the external table
definition does not persist in the system catalog.
--transient external table
SELECT
employee_id,
employee_name,
salary
FROM EXTERNAL 'c:\temp\testfile.txt'
(
employee_id integer,
employee_name character varying(100),
salary decimal (10,2))
USING (
remotesource 'odbc'
delimiter ','
skiprows 1);
Transient external table is also a very useful way to export data from a
netezza database out to a text file. You can export not just an entire
table, but the output of any sql statement. The beauty of it is you
don't have to specify the schema definition of the data, which can save
you a lot of typing:
create table mytesttable (
studentid integer,
studentname character varying(100)
);
insert into mytesttable
select 1, 'Jane Doe'
union
select 2, 'John Smith';
CREATE EXTERNAL TABLE 'c:\Temp\ExportDataTest.csv' USING (remotesource 'ODBC' DELIM ',') AS
SELECT *
from mytesttable;
drop table mytesttable;
Note: if the file already exists, any existing data will be deleted by Netezza before it inserts data.
If there's comma in your data, and you want to export to csv, use escapeChar option:
CREATE EXTERNAL TABLE 'c:\Temp\OfferAttributesNightlyFeed.csv' USING (remotesource 'ODBC' DELIM ',' ESCAPECHAR '\') AS
SELECT *
from COUPONATTRIBUTESTEST;
相关文章推荐
- how to use sqlserver2008 to search in files
- R Markdown: How to format tables and figures in .docx files
- How to use an external dll file in VisualStudio project
- How to Use Rsync to Sync New or Changed/Modified Files in Linux
- How to use logrotate to manage log files in Linux
- How to use an external dll file in VisualStudio project
- [转]How to Use xp_dirtree to List All Files in a Folder
- How to use logrotate to manage log files in linux(如何在Linux中使用logrotate去管理日志文件)
- How to View MySQL Temp Files and Temp Tables in Linux
- how to use deb files in ubuntu
- How to use outline levels to create a table of contents (TOC) in Word 2003 and in Word 2002
- How to create a project with existing folder of files in Visual Studio?
- How to use pthread in cocos2d-x
- How to use SCAT in ECC6
- How to use the ZooKeeper driver for ServiceGroup in OpenStack Nova
- How To Use DBLink In Oracle Forms 6i
- How To Use The New Multivalue Field In Access 2007/2010 Sunday, June 19th, 2011
- ORA-14450: attempt to access a transactional temp table already in use
- how to count files in directory
- how to use Gesture in Iphone