INSERT keyword
INSERT ingests selected data into a database table.
Syntax#
Inserting values directly or using sub-queries:
Inserting using sub-query alias:
Description#
note
If the target partition is
attached by a symbolic link,
the partition is read-only. INSERT operation on a read-only partition triggers
a critical-level log in the server, and the insert is a no-op.
Inserting values directly or using sub-queries:
- VALUE: Directly defines the values to be inserted.
- SELECT: Inserts values based on the result of a SELECT query
Setting sub-query alias:
- WITH AS: Inserts values based on a sub-query, to which an alias is given by using WITH.
Parameter:
- batchexpects a- batchCount(integer) value defining how many records to process at any one time.
Examples#
note
Columns can be omitted during INSERT in which case the value will be NULL
Inserting query results#
This method allows you to insert as many rows as your query returns at once.
Using the WITH keyword to set up an alias for a
SELECT sub-query:
Parameters for QuestDB 6.5.5 and earlier versions#
note
Deprecated content
This section applies to QuestDB 6.5.5 and earlier versions. From QuestDB 6.6 onwards, the database adjusts relevant settings automatically and provides maximum ingestion speed.
Inserting values directly or using sub-queries:
Inserting using sub-query alias:
The commitLag parameter may be provided to optimize INSERT AS SELECT or
WITH AS queries when inserting
out-of-order records into an ordered
dataset:
- commitLagexpects a- lagAmountwith a modifier to specify the time unit for the value (i.e.- 20sfor 20 seconds). The following table describes the units that may be used:- unit - description - us - microseconds - s - seconds - m - minutes - h - hours - d - days