INSERT¶
SQL command to insert rows in a given table. Rows to be inserted can be expressed via a VALUES clause or via a dedicated query.
Syntax¶
Parameters¶
tableNameThe name of the target table
columnNameThe name of one of the target column in the target table
literalA literal whose type must be compatible with the target column
queryA query whose result can be used to insert into the target table
Examples¶
Insert a single row¶
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
INSERT INTO T VALUES (3, 'three', 3.0);
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
Insert multiple rows¶
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
INSERT INTO T VALUES (3, 'three', 3.0), (4, 'four', 4.0);
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Insert new rows without specifying all columns¶
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
INSERT INTO T(A, B) VALUES (3, 'three'), (4, 'four');
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Insert rows in a table with a STRUCT column¶
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
INSERT INTO T VALUES (3, 'three', (30, 300)), (4, 'four', (40, 400));
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Insert rows in a table with an ARRAY column¶
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
INSERT INTO T VALUES (3, 'three', [30, 300, 3000]), (4, 'four', [40, 400, 4000, 40000]);
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Insert from query¶
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
INSERT INTO T SELECT 3, B, C FROM T WHERE C.S1 = 20
SELECT * FROM T;
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|