version 11
INSERT INTO {sql_name | sql_string}
[(column_reference, ..., column_reference)]
{VALUES({arithmetic_expression |NULL}, ..., {arithmetic_expression |NULL}) |subquery}
Description
The INSERT command is used to add data to an existing table. The table where the data is to be added is passed either using an sql_name or sql_string. The optional column_reference type arguments passed indicate the name(s) of the column(s) where the values are to be inserted. If no column_reference is passed, the value(s) inserted will be stored in the same order as in the database (1st value passed goes into 1st column, 2nd value into 2nd column, and so on).
The VALUES keyword is used to pass the value(s) to be placed in the column(s) specified. You can either pass an arithmetic_expression or NULL. Alternatively, a subquery can be passed in the VALUES keyword in order to insert a selection of data to be passed as the values.
The number of values passed in the VALUES keyword must match the number of columns specified by the column_reference type argument(s) passed and each of them must also match the data type of the corresponding column or at least be convertible to that data type.
The INSERT command is supported in both single- and multi-row queries. However, a multi-row INSERT statement does not allow UNION and JOIN operations.
Examples
1. Here is a simple example inserting a selection from table2 into table1:
INSERT INTO table1 (SELECT * FROM table2)
2. This example creates a table and then inserts values into it:
CREATE TABLE ACTOR_FANS (ID INT32, Name VARCHAR); INSERT INTO ACTOR_FANS (ID, Name) VALUES (1, 'Francis');
See Also
arithmetic_expression, column_reference, DELETE, subquery.