17.10 - Create Foreign Table - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1144-171K
Language
English (United States)

The following statement defines a foreign table using the authorization object called MyAuthObj. The foreign table is for CSV formatted river flow data stored in an Amazon S3 bucket.

CREATE FOREIGN TABLE riverflow_csv,
  EXTERNAL SECURITY MyAuthObj
  USING (
    LOCATION ('/s3/YOUR-BUCKET.s3.amazonaws.com/CSVDATA/09513780/')
  );

The following statement shows the new foreign table:

SHOW TABLE riverflow_csv;

Result:

CREATE MULTISET FOREIGN TABLE NU.riverflow_csv ,FALLBACK ,
     EXTERNAL SECURITY MyAuthObj ,
     MAP = TD_MAP1
     (
      Location VARCHAR(2048) CHARACTER SET UNICODE CASESPECIFIC,
      GageHeight2 DECIMAL(3,2),
      Flow DECIMAL(3,2),
      site_no INTEGER,
      datetime TIMESTAMP(0) FORMAT 'Y4-MM-DDBHH:MI',
      Precipitation DECIMAL(3,2),
      GageHeight DECIMAL(3,2))
  
USING
(
      LOCATION  ('/s3/YOUR-BUCKET.s3.amazonaws.com/CSVDATA/')
      MANIFEST  ('FALSE')
      PATHPATTERN  ('$var1/$site_no/$var3/$var4/$var5')
      ROWFORMAT  ('{"field_delimiter":",","record_delimiter":"\n","character_set":"LATIN"}')
      STOREDAS  ('TEXTFILE')
      HEADER  ('TRUE')
      STRIP_EXTERIOR_SPACES  ('FALSE')
      STRIP_ENCLOSING_CHAR  ('NONE')
)
NO PRIMARY INDEX ;