title sidebar_label description
INSERT keyword INSERT INSERT SQL keyword reference documentation.

Inserts data into a database table.

Syntax

Flow chart showing the syntax of the INSERT keyword

Parameters

Two parameters may be provided to optimize INSERT AS SELECT queries when inserting out-of-order records into an ordered dataset:

  • batch expects a batchCount (integer) value how many records to process at any one time
  • lag expects a lagAmount (integer) value in microseconds which specifies the expected lateness of out-of-order records

Examples


1. INSERT INTO trades
2. VALUES(
3. to_timestamp('2019-10-17T00:00:00', 'yyyy-MM-ddTHH:mm:ss'),
4. 'AAPL',
5. 255,
6. 123.33,
7. 'B');


1. INSERT INTO trades (timestamp, symbol, quantity, price, side)
2. VALUES(
3. to_timestamp('2019-10-17T00:00:00', 'yyyy-MM-ddTHH:mm:ss'),
4. 'AAPL',
5. 255,
6. 123.33,
7. 'B');

:::note

Columns can be omitted during INSERT in which case value will be NULL

:::


1. INSERT INTO trades (timestamp, symbol, price)
2. VALUES(to_timestamp('2019-10-17T00:00:00', 'yyyy-MM-ddTHH:mm:ss'),'AAPL','B');

Inserting query results

This method allows you to insert as many rows as your query returns at once.


1. INSERT INTO confirmed_trades
2. SELECT timestamp, instrument, quantity, price, side
3. FROM unconfirmed_trades
4. WHERE trade_id = '47219345234';

Inserting out-of-order data into an ordered dataset may be optimized using batch and lag parameters:


1. INSERT batch 100000 lag 180000000 INTO trades
2. SELECT ts, instrument, quantity, price
3. FROM unordered_trades

:::info

Hints and an example workflow using INSERT AS SELECT for bulk CSV import of out-of-order data can be found on the importing data via CSV documentation.

:::