Transient external tables
Transient external tables (TETs) provide a way to define an external table that exists only for the duration of a single query.
TETs have the same capabilities and limitations as normal external tables. A special feature of a TET is that you do not need to define the table schema when you use the TET to load data into a table or when you create the TET as the target of a SELECT statement.
Syntax
INSERT INTO <table> SELECT <column_list | *>
FROM EXTERNAL 'filename' [(table_schema_definition)]
[USING (external_table_options)];
CREATE EXTERNAL TABLE 'filename' [USING (external_table_options)]
AS select_statement;
SELECT <column_list | *> FROM EXTERNAL 'filename' (table_schema_definition)
[USING (external_table_options)];
For information about the values that you can specify for the external_table_options variable, see External table options.
Explicit table schema definition
SELECT x, y, NVL(dt, current_date) AS dt FROM EXTERNAL '/tmp/test.txt'
( x integer, y numeric(18,4), dt date ) USING (DELIM ',');
SELECT * FROM EXTERNAL '/tmp/fixed.txt' ( x integer, y numeric(18,4),
dt date ) USING (FORMAT 'fixed' LAYOUT (bytes 4, bytes 20, bytes 10));
SELECT * FROM EXTERNAL '/tmp/test.txt' SAMEAS test_table
USING (DELIM ',');
Implicit table schema definition
If you do not explicitly define the TET schema, the schema is determined based on the query that is executing. When you use a TET as a data source for an INSERT statement, the external table uses the schema of the target table.
INSERT INTO target SELECT * FROM external '/tmp/data.txt'
USING (DELIM '|');
Unloading data by using TETs
You can use a TET to unload data from a database. In this case, the schema of the external table is based on the query that is executing. An example follows:
CREATE EXTERNAL TABLE '/tmp/export.csv' USING (DELIM ',') AS
SELECT foo.x, bar.y, bar.dt FROM foo, bar WHERE foo.x = bar.x;
Remote TETs
If you establish a connection to the system from a client machine by using ODBC, JDBC, OLE DB, or the nzsql command, you can unload data into a remote TET or load data from a remote TET. When creating the remote TET, specify the REMOTESOURCE option in the USING clause.
CREATE TEMP TABLE mydata AS SELECT cust_id, upper(cust_name) as name
from external 'c:\customer\data.csv' (cust_id integer, cust_name
varchar(100)) USING (DELIM ',' REMOTESOURCE 'ODBC');
Remote external table loads work by sending the contents of a file from the client system to the Netezza Performance Server system where the data is then parsed. This method minimizes CPU usage on the client system.