Documentation — Commands reference

insert

Adds one row to a table.

Syntax

insert into TABLE_NAME [ ( COL1, COL2, ... ) ] values ( VAL1, VAL2, ... );
  • Without the list of columns, values must give a value for every column, in the order of the table.
  • The statement must give a value to every column of the hash key, because the key decides where the row goes.
  • One row per statement. You cannot insert the result of a select.
  • You need the INSERT privilege. The table must be deployed and not locked.
insert into visitors values ( 1, 'Ada', 'FR' );
insert into visitors ( id, name ) values ( 2, 'Grace' );

The answer is One row inserted., followed by the number of errors if some copies could not be written.

Hash key values

  • A NULL is accepted in a hash key column: the word NULL is hashed like any other value.
  • A value can be an expression such as 2+3; its result is used. If you need every row with the same key to land in the same partition, do not use an expression in the hash key: write the plain value.

Narrow tables

The row goes to its partition, on every copy of that partition.

Wide tables

The row is cut into its chunks and every chunk goes to its own segment, so one insert costs more than for a narrow table: about 1.2 to 1.5 seconds from the command line client on the test tables of 20,001 and 585,011 columns.

The statement can be very long: a row of a table with 585,011 columns is several megabytes of text.

← grant  |  lock →