Use INSERT SELECT to Load CSV | Native Object Store ( NOS ) | Teradata Vantage - 17.05 - Loading External Data into the Database Using INSERT SELECT - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - Native Object Store Getting Started Guide

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1214-175K
Language
English (United States)

This example illustrates how a subset of the payload attributes for a single siteno value can be stored in a persistent database table using an INSERT SELECT statement.

The examples use a sample river flow data set. To use your own data, replace the table and column names, and authorization object. See Variable Substitutions for Examples for the credentials and location values for the sample data set.

  1. To run NOS-related commands, log on to the database as a user with the required privileges.
  2. If it does not exist, create the foreign table or ask your database administrator to create the foreign table called riverflow_csv. See Setting Up to Run CSV Examples.
  3. In this example, data from a single site number is loaded into the database. Create the permanent table to store the external data:
    CREATE TABLE RiverFlowPermInsert_csv
    (DateTS CHAR(20)
    ,SiteNo CHAR(8)
    ,Flow FLOAT FORMAT '-ZZZZ9.99'
    ,Velocity FLOAT FORMAT '-ZZZ9.99'
    ,GageHeight FLOAT FORMAT '-ZZZ9.99'
    ,Temp FLOAT FORMAT '-ZZZ9.99') 
    PRIMARY INDEX (SiteNo);
  4. Insert the external data into the database table:
    INSERT INTO RiverFlowPermInsert_csv
    SELECT
    payload..datetime
    ,payload..site_no
    ,Cast (payload..Flow AS FLOAT)
    ,Cast (payload..Velocity AS FLOAT)
    ,Cast (payload..GageHeight AS FLOAT)
    ,Cast (payload..Temp AS FLOAT)
    WHERE payload..site_no = '09429070'
    FROM riverflow_csv;
  5. Query the data from the database table:
    SELECT TOP 2 * FROM RiverFlowPermInsert_csv;

    Your result will be similar to the following:

    DateTS                SiteNo        Flow  Velocity  GageHeight     Temp
    --------------------  --------  --------  --------  ----------  -------
    2018-07-02 01:00      09429070    149.00      0.78        5.75    78.80
    2018-07-02 00:30      09429070    145.00      0.77        5.68    78.90