Example: Using the DEFAULT Function with INSERT ... SELECT - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-04-05
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantage™

Assume the following table definitions for this example:

     CREATE TABLE tbl_source (
       col1 INTEGER,
       col2 INTEGER DEFAULT 10,
       col3 INTEGER DEFAULT 20,
       col4 CHARACTER(60));

     CREATE TABLE tbl_destination (
       col1 INTEGER,
       col2 INTEGER DEFAULT 10,
       col3 INTEGER DEFAULT 20,
       col4 CHARACTER(60));

The following example shows correct use of the DEFAULT function within an INSERT ... SELECT request:

     INSERT INTO tbl_destination (col1)
     SELECT COALESCE(col3, DEFAULT(col3)) END
     FROM tbl_source
     WHERE col3 <> DEFAULT;

In this example, the DEFAULT function evaluates to a constant value, which is the default value of col3 of tbl_source.