Example: INSERT Using a Scalar Subquery - Teradata Database - Teradata Vantage NewSQL Engine

SQL Data Manipulation Language

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-03
dita:mapPath
fbo1512081269404.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

A scalar subquery can be specified as a parameterized value in the value list of a simple INSERT request, but Teradata Database always interprets it as a noncorrelated scalar subquery.

For example, Teradata Database processes the scalar subquery SELECT d2 FROM t2 WHERE a2=t1.a1 in the select list of the following INSERT request as if it were SELECT d2 FROM t2, t1 WHERE a2=t1.a1.

In other words, Teradata Database interprets t1 in the scalar subquery as a distinct instance of t1 rather than as the target table t1 of the insert operation.

     INSERT INTO t1 VALUES (1,2,3 (SELECT d2
                                   FROM t2
                                   WHERE a2=t1.a1));