INSERT
command inserts one or more rows into an existing table. The values inserted into each column in the table can either be explicitly-specified using the VALUES
keyword, or use the result of a query.
table_name
The name of the table to be inserted with the new rows.
alias
A substitute alias name for table_name
. The alias name should match the Identifiers Limitations.
column_name
A list of columns in the table. The columns can be listed in any order, as long as the expressions in the VALUES clause are listed in the same order. Each missing column is set to NULL
or to its default value specified in the CREATE TABLE
statement. In case of a missing column that has no default value and the column has a NOT NULL
constraint, the command fails.
This parameter is optional. If no column names were specified, the values are assigned to the columns in the order of columns defined in the table’s creation. If the number of values is less than the number of columns, the values are assigned to the first columns and the rest are assigned default values, or NULL
for columns with no default value.
VALUES
Specifies the values to insert into the corresponding columns in the table. The data types of the values should be compatible with the data types of the corresponding columns in the column list (note that in some cases, Regatta will overcome mismatches with implicit conversion).
The list of values can only contain literals (e.g. ‘hello’), the DEFAULT
and NULL
keywords, expressions or functions that can be computed at the planning time such as NOW()
or 5*50.
String literals and date literals in the VALUES
list must be enclosed by single quotes (’).
expression
An expression or value to assign to the corresponding column. The expression is given as a string and Regatta attempts to convert it to the desired data type.
DEFAULT
Store the column default value as it’s defined for the column at the CREATE TABLE or ALTER TABLE
statements.
Note that if all the columns in the table have DEFAULT
values, the following syntax can be used to insert a single row with all the columns set to the default values: INSERT INTO <table name> DEFAULT VALUES;
query
A SELECT statement that supplies the rows to be inserted. See SELECT.
WITH devices = ( device_list ) IN MODULES ( module_list )
Regatta uses an internal algorithm to distribute the rows of a table across the table storage devices optimally. You can override it by specifying one or more device into which the rows will be inserted. The devices are identified by their internal device number within the pertinent modules, and modules containing the devices should also be specified.
Use of this clause is generally discouraged as it could interfere with Regatta’s internal data distribution algorithms and degrade performance and/or cause a storage device to fill up unintentionally. It should be used with care in very specific use cases.
RETURNING output_expression
Returns the given expression for every row inserted by the command. Refer to the expression
parameter of SELECT for specification of the output_expression parameter.
If only ROWID
is specified as the output_expression, the returned ROWIDs are returned in pairs of
(First ROWID, number of rows) for each set of consecutive ROWID numbers.
INSERT
command returns the count of the inserted rows.
o_date
is loaded with its DEFAULT value as defined in the table definition.
Missing columns (o_totalprice
) will write their default value, or NULL. If no DEFAULT was defined and the column is set with the NOT NULL constraint, the INSERT
will fail.
Insert based on a query result:
INSERT
command conforms to the SQL standard with the exception of the RETURNING
functionality.