INSERT

Documentation

Home » Documentation » Using VoltDB

INSERT

INSERT — Creates a new row in the database, using the specified values for the columns.

Synopsis

INSERT INTO table-name [( column-name [,...] )] VALUES ( value-expression [,...] )

Description

The INSERT statement creates a new row in the database. If you specify the column names, the values will be assigned to the columns in the order specified. If you do not specify the column names, values will be assigned to columns based on the order specified in the schema definition.

You can specify a subset of the columns in the table by specifying the column names and their desired values. However, you must specify values for any columns that are explicitly defined in the schema as NOT NULL and do not have a default value assigned.

VoltDB supports the following arithmetic operators in expressions: addition (+), subtraction (-), multiplication (*), and division (*).

Examples

The following example inserts values into the columns (firstname, mi, lastname, and emp_id) of an EMPLOYEE table:

INSERT INTO employee VALUES ('Jane', 'Q', 'Public', 145303);

The next example performs the same operation with the same results, except this INSERT statement explicitly identifies the column names and changes the order:

INSERT INTO employee (emp_id, lastname, firstname, mi) 
       VALUES (145303, 'Public', 'Jane', 'Q');

The last example assigns values for the employee ID and the first and last names, but not the middle initial. This query will only succeed if the MI column is nullable or has a default value defined in the database schema.

INSERT INTO employee (emp_id, lastname, firstname) 
       VALUES (145304, "Doe", "John");