Creating External Tables - Examples
Note: When using IPv6, always enclose the numeric IP addresses in square brackets.
Start gpfdist
before you create external tables with the gpfdist
protocol. The following code starts the gpfdist
file server program in the background on port 8081 serving files from directory /var/data/staging
. The logs are saved in /home/gpadmin/log
.
Creates a readable external table, ext_expenses
, using the gpfdist
protocol. The files are formatted with a pipe (|) as the column delimiter.
=# CREATE EXTERNAL TABLE ext_expenses
( name text, date date, amount float4, category text, desc1 text )
LOCATION ('gpfdist://etlhost-1:8081/*')
Example 2 - Multiple gpfdist instances
=# CREATE EXTERNAL TABLE ext_expenses
LOCATION ('gpfdist://etlhost-1:8081/*.txt', 'gpfdist://etlhost-2:8081/*.txt')
FORMAT 'TEXT' ( DELIMITER '|' NULL ' ') ;
Creates a readable external table, ext_expenses, from all files with the txt extension using the gpfdists
protocol. The column delimiter is a pipe ( | ) and NULL is a space (’ ’). For information about the location of security certificates, see .
- Run
gpfdist
with the--ssl
option. Run the following command.
Example 4 - Single gpfdist instance with error logging
Uses the gpfdist protocol to create a readable external table, ext_expenses,
from all files with the txt extension. The column delimiter is a pipe ( | ) and NULL (’ ’) is a space.
=# CREATE EXTERNAL TABLE ext_expenses
( name text, date date, amount float4, category text, desc1 text )
LOCATION ('gpfdist://etlhost-1:8081/*.txt', 'gpfdist://etlhost-2:8082/*.txt')
FORMAT 'TEXT' ( DELIMITER '|' NULL ' ')
LOG ERRORS INTO expenses_errs SEGMENT REJECT LIMIT 5;
To create the readable ext_expenses
table from CSV-formatted text files:
( name text, date date, amount float4, category text, desc1 text )
LOCATION ('gpfdist://etlhost-1:8081/*.txt', 'gpfdist://etlhost-2:8082/*.txt')
FORMAT 'CSV' ( DELIMITER ',' )
LOG ERRORS INTO expenses_errs SEGMENT REJECT LIMIT 5;
Creates a readable web external table that executes a script once on five virtual segments:
Example 6 - Writable External Table with gpfdist
Creates a writable external table, sales_out, that uses gpfdist
to write output data to the file sales.out. The column delimiter is a pipe ( | ) and NULL is a space (’ ’). The file will be created in the directory specified when you started the gpfdist file server.
=# CREATE WRITABLE EXTERNAL TABLE sales_out (LIKE sales)
LOCATION ('gpfdist://etl1:8081/sales.out')
FORMAT 'TEXT' ( DELIMITER '|' NULL ' ')
DISTRIBUTED BY (txn_id);
=# CREATE WRITABLE EXTERNAL WEB TABLE campaign_out
(LIKE campaign)
Example 8 - Readable and Writable External Tables with XML Transformations
HAWQ can read and write XML data to and from external tables with gpfdist. For information about setting up an XML transform, see .