Transient external tables (TET) provide a way to define an external table that exists only for the duration of a single query.
Transient external tables have the same capabilities and limitations as normal external tables. A special feature of a TET is that the table schema does not need to be defined when the TET is used to load data into a table or when the TET is created as the target of a SELECT statement.
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)];
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 ',');
If the transient external table schema is not explicitly defined, the schema is determined based on the query that is executing. When a TET is used 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 '|');
A transient external table can also be used to export data out of the database. In this case, the schema of the external table is based on the query that is executing. For example:
CREATE EXTERNAL TABLE '/tmp/export.csv' USING (DELIM ',') AS
SELECT foo.x, bar.y, bar.dt FROM foo, bar WHERE foo.x = bar.x;
A session connected to IBM® Netezza® using ODBC, JDBC, or OLE DB from a client system can import and export data by using a remote transient external table, which is defined by using 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 server where the data is then parsed. This method minimizes CPU usage on the client system during a remote external table load.