External web tables allow Greenplum Database to treat dynamic data sources like regular database tables. Because web table data can change as a query runs, the data is not rescannable.

CREATE EXTERNAL WEB TABLE creates a web table definition. You can define command-based or URL-based external web tables. The definition forms are distinct: you cannot mix command-based and URL-based definitions.

Parent topic: Defining External Tables

Command-based External Web Tables

The output of a shell command or script defines command-based web table data. Specify the command in the EXECUTE clause of CREATE EXTERNAL WEB TABLE. The data is current as of the time the command runs. The EXECUTE clause runs the shell command or script on the specified master, and/or segment host or hosts. The command or script must reside on the hosts corresponding to the host(s) defined in the EXECUTE clause.

By default, the command is run on segment hosts when active segments have output rows to process. For example, if each segment host runs four primary segment instances that have output rows to process, the command runs four times per segment host. You can optionally limit the number of segment instances that run the web table command. All segments included in the web table definition in the ON clause run the command in parallel.

The command that you specify in the external table definition is run from the database and cannot access environment variables from .bashrc or .profile. Set environment variables in the EXECUTE clause. For example:

  1. =# CREATE EXTERNAL WEB TABLE output (output text)
  2. EXECUTE 'PATH=/home/gpadmin/programs; export PATH; myprogram.sh'
  3. FORMAT 'TEXT';

Scripts must be executable by the gpadmin user and reside in the same location on the master or segment hosts.

The following command defines a web table that runs a script. The script runs on each segment host where a segment has output rows to process.

  1. =# CREATE EXTERNAL WEB TABLE log_output
  2. (linenum int, message text)
  3. EXECUTE '/var/load_scripts/get_log_data.sh' ON HOST
  4. FORMAT 'TEXT' (DELIMITER '|');

URL-based External Web Tables

A URL-based web table accesses data from a web server using the HTTP protocol. Web table data is dynamic; the data is not rescannable.

Specify the LOCATION of files on a web server using http://. The web data file(s) must reside on a web server that Greenplum segment hosts can access. The number of URLs specified corresponds to the number of segment instances that work in parallel to access the web table. For example, if you specify two external files to a Greenplum Database system with eight primary segments, two of the eight segments access the web table in parallel at query runtime.

The following sample command defines a web table that gets data from several URLs.

  1. =# CREATE EXTERNAL WEB TABLE ext_expenses (name text,
  2. date date, amount float4, category text, description text)
  3. LOCATION (
  4. 'http://intranet.company.com/expenses/sales/file.csv',
  5. 'http://intranet.company.com/expenses/exec/file.csv',
  6. 'http://intranet.company.com/expenses/finance/file.csv',
  7. 'http://intranet.company.com/expenses/ops/file.csv',
  8. 'http://intranet.company.com/expenses/marketing/file.csv',
  9. 'http://intranet.company.com/expenses/eng/file.csv'
  10. )
  11. FORMAT 'CSV' ( HEADER );