Skip to main content

Insert Into Values

The INSERT INTO VALUES statement loads inline values from SQL into a warehouse table. It is a synchronous load method that returns the load result directly after execution, so you can determine whether the load succeeded based on the response. This method guarantees the atomicity of the load task: all accepted rows commit together, or the transaction fails. Configured filters can reject rows before commit.

Run these statements in SQL Editor or a connected SQL client in a running SaaS or BYOC warehouse. Create testdb if needed. You need CREATE to create the example table and LOAD (also accepted as INSERT) to write to it. The examples use ordinary synchronous inserts. Group Commit can change acknowledgment and visibility behavior, so check its mode before applying the synchronous examples.

Example responses below are illustrative. IDs, timings, hosts, and row counts depend on your load.

Use cases​

Use INSERT INTO VALUES for the following scenarios:

ScenarioDescription
Feature validation / DemoLoad a small amount of mock data to validate VeloDB Cloud features. The syntax is consistent with MySQL.
Small-batch data ingestionUse it in scenarios with low concurrency and small data volume.

Tip:

Batch frequent writes

Frequent small inserts can spend a substantial share of their time committing transactions. Evaluate Group Commit with representative data and the acknowledgment mode required by your application.

How it works​

INSERT INTO VALUES sends jobs to the FE node for execution through the MySQL protocol. The overall flow is as follows:

  1. The client submits the INSERT INTO VALUES statement to the FE through the MySQL protocol.
  2. The FE generates an execution plan: the front part contains query-related operators, and the last operator is OlapTableSink, which writes the query result into the target table.
  3. The FE dispatches the execution plan to BE nodes for execution and selects one BE as the Coordinator node.
  4. The Coordinator node receives the data and distributes it to other BE nodes to complete the write.

Quick start​

INSERT INTO VALUES is submitted through the MySQL protocol. The example below uses the MySQL command line to demonstrate the full submission flow. For detailed syntax, see INSERT INTO.

Prerequisites​

Executing INSERT INTO VALUES requires the INSERT privilege on the target table. If the current user does not have this privilege, use the GRANT command to grant it.

Create a load job​

Step 1: create the target table​

CREATE TABLE testdb.test_table(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "name",
age INT COMMENT "age"
)
DUPLICATE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 10;

Step 2: run INSERT INTO VALUES to write data​

Note:

Choose a batch method

Use INSERT INTO VALUES for small application writes and test data. For frequent small batches, evaluate Group Commit. For bulk files, use Stream Load or Broker Load.

INSERT INTO testdb.test_table (user_id, name, age)
VALUES (1, "Emily", 25),
(2, "Benjamin", 35),
(3, "Olivia", 28),
(4, "Alexander", 60),
(5, "Ava", 17);

As a synchronous load method, the result is returned directly to the client:

Query OK, 5 rows affected (0.308 sec)
{'label':'label_26eebc33411f441c_b2b286730d495e2c', 'status':'VISIBLE', 'txnId':'61071'}

Step 3: verify the loaded data​

MySQL> SELECT COUNT(*) FROM testdb.test_table;
+----------+
| count(*) |
+----------+
| 5 |
+----------+
1 row in set (0.179 sec)

View the load job​

Use the SHOW LOAD command to view completed INSERT INTO VALUES jobs:

mysql> SHOW LOAD FROM testdb\G
*************************** 1. row ***************************
JobId: 77172
Label: label_26eebc33411f441c_b2b286730d495e2c
State: FINISHED
Progress: Unknown id: 77172
Type: INSERT
EtlInfo: NULL
TaskInfo: cluster:N/A; timeout(s):14400; max_filter_ratio:1.0
ErrorMsg: NULL
CreateTime: 2024-11-20 16:44:08
EtlStartTime: 2024-11-20 16:44:08
EtlFinishTime: 2024-11-20 16:44:08
LoadStartTime: 2024-11-20 16:44:08
LoadFinishTime: 2024-11-20 16:44:08
URL:
JobDetails: {"Unfinished backends":{},"ScannedRows":0,"TaskNumber":0,"LoadBytes":0,"All backends":{},"FileNumber":0,"FileSize":0}
TransactionId: 61071
ErrorTablets: {}
User: root
Comment:
1 row in set (0.00 sec)

Cancel the load job​

In the MySQL client, use Ctrl-C to cancel a currently running INSERT INTO VALUES job.

Reference​

Load command syntax​

INSERT INTO target_table (col1, col2, ...)
VALUES (val1, val2, ...), (val3, val4, ...), ...;

Note:

Use small batches with INSERT INTO VALUES. For bulk loading, choose a dedicated load method and test batch size and concurrency.

Load configuration parameters​

Defaults below are compiled values checked in Core 26.1.3, not verified settings of your warehouse. Check session values with SHOW VARIABLES. FE settings are service-managed. If a service setting needs adjustment, contact VeloDB Cloud support.

Service-managed FE configuration​

ParameterDefault valueDescription
insert_load_default_timeout_second14400 (4 hours)Timeout of the load task, in seconds. If the load task does not complete within this timeout, the system cancels it and the status changes to CANCELLED.

Session variables​

ParameterDefault valueDescription
insert_timeout14400 (4 hours)Timeout when INSERT INTO is executed as a SQL statement, in seconds.
enable_insert_stricttrueWhen set to true, the load fails if any unqualified data is encountered. When set to false, unqualified rows can be filtered. The filtered-row ratio is checked before commit.
insert_max_filter_ratio1.0Takes effect only when enable_insert_strict=false. Controls the maximum proportion of filtered rows for INSERT INTO ... VALUES and INSERT INTO ... SELECT, including queries from warehouse tables, external tables, and file table-valued functions such as S3, HDFS, and LOCAL. The value range is 0 to 1. The insert fails when filtered_rows / (loaded_rows + filtered_rows) exceeds this value. The compiled default 1.0 allows all rows eligible for filtering to be rejected. It does not suppress other execution errors.

Note:

Common causes of unqualified data

The source column length exceeds the target column length, column types do not match, partitions do not match, column order does not match, and so on.

Load return values​

INSERT INTO VALUES is a SQL statement. The result contains a JSON string with the following fields:

ParameterDescription
LabelThe label of the load job. It can be specified with INSERT INTO tbl WITH LABEL label ....
StatusThe visibility status of the loaded data:
- visible: the load succeeded and the data is visible.
- committed: the transaction has committed, but the data may not yet be visible. No retry is needed.
- Label Already Exists: the label is already in use. Check the existing job or transaction before retrying.
- Fail: the load failed.
ErrError message of the load.
TxnIdThe ID of the load transaction.

The following examples illustrate four typical return scenarios. For the unqualified table names in these examples, first select the example database with USE testdb;.

Scenario 1: INSERT executed successfully​

INSERT executed successfully
mysql> INSERT INTO test_table (user_id, name, age) VALUES (1, "Emily", 25), (2, "Benjamin", 35), (3, "Olivia", 28), (4, "Alexander", 60), (5, "Ava", 17);
Query OK, 5 rows affected (0.05 sec)
{'label':'label_26eebc33411f441c_b2b286730d495e2c', 'status':'VISIBLE', 'txnId':'61071'}
  • Query OK: indicates the statement was executed successfully.
  • 5 rows affected: indicates a total of 5 rows were loaded.

Scenario 2: INSERT executed successfully with warnings​

INSERT executed successfully with warnings

This example assumes enable_insert_strict=false and a filter ratio that permits one rejected row out of five. The NULL value violates the example table's NOT NULL key. Restore your original settings after testing.

mysql> INSERT INTO test_table (user_id, name, age) VALUES (1, "Emily", 25), (2, "Benjamin", 35), (3, "Olivia", 28), (NULL, "Alexander", 60), (5, "Ava", 17);
Query OK, 4 rows affected, 1 warning (0.04 sec)
{'label':'label_a8d99ae931194d2b_93357aac59981a18', 'status':'VISIBLE', 'txnId':'61068'}
  • Query OK: indicates the statement was executed successfully.
  • 4 rows affected: indicates a total of 4 rows were loaded.
  • 1 warning: indicates 1 row was filtered out.

Use the SHOW LOAD statement to find the job's diagnostic URL, then use it to query the error data. See View error rows.

mysql> SHOW LOAD WHERE label="label_a8d99ae931194d2b_93357aac59981a18"\G
*************************** 1. row ***************************
JobId: 77158
Label: label_a8d99ae931194d2b_93357aac59981a18
State: FINISHED
Progress: Unknown id: 77158
Type: INSERT
EtlInfo: NULL
TaskInfo: cluster:N/A; timeout(s):14400; max_filter_ratio:1.0
ErrorMsg: NULL
CreateTime: 2024-11-20 16:35:40
EtlStartTime: 2024-11-20 16:35:40
EtlFinishTime: 2024-11-20 16:35:40
LoadStartTime: 2024-11-20 16:35:40
LoadFinishTime: 2024-11-20 16:35:40
URL: <error-log-url>
JobDetails: {"Unfinished backends":{},"ScannedRows":0,"TaskNumber":0,"LoadBytes":0,"All backends":{},"FileNumber":0,"FileSize":0}
TransactionId: 61068
ErrorTablets: {}
User: root
Comment:
1 row in set (0.00 sec)

Scenario 3: INSERT executed successfully but status is committed​

INSERT executed successfully but status is committed
mysql> INSERT INTO test_table (user_id, name, age) VALUES (1, "Emily", 25), (2, "Benjamin", 35), (3, "Olivia", 28), (4, "Alexander", 60), (5, "Ava", 17);
Query OK, 5 rows affected (0.04 sec)
{'label':'label_78bf5396d9594d4d_a8d9a914af40f73d', 'status':'COMMITTED', 'txnId':'61074'}

COMMITTED means the transaction has committed but is not yet visible. Do not resubmit it with a new label. Use the SHOW TRANSACTION statement to check the visibility status. When the TransactionStatus column becomes VISIBLE, the data is visible.

mysql> SHOW TRANSACTION WHERE id=61074\G
*************************** 1. row ***************************
TransactionId: 61074
Label: label_78bf5396d9594d4d_a8d9a914af40f73d
Coordinator: FE: <managed-frontend>
TransactionStatus: VISIBLE
LoadJobSourceType: INSERT_STREAMING
PrepareTime: 2024-11-20 16:51:54
PreCommitTime: NULL
CommitTime: 2024-11-20 16:51:54
PublishTime: 2024-11-20 16:51:54
FinishTime: 2024-11-20 16:51:54
Reason:
ErrorReplicasCount: 0
ListenerId: -1
TimeoutMs: 14400000
ErrMsg:
1 row in set (0.00 sec)

Scenario 4: INSERT execution failed​

INSERT execution failed

This example assumes enable_insert_strict=false and insert_max_filter_ratio=0.1. One invalid row out of five exceeds that ratio.

A failed execution means no data was loaded successfully:

mysql> INSERT INTO test_table (user_id, name, age) VALUES (1, "Emily", 25), (2, "Benjamin", 35), (3, "Olivia", 28), (NULL, "Alexander", 60), (5, "Ava", 17);
ERROR 1105 (HY000): errCode = 2, detailMessage = Insert has too many filtered data 1/5 insert_max_filter_ratio is 0.100000. url: <error-log-url>
  • ERROR 1105 (HY000): errCode = 2, detailMessage = Insert has too many filtered data 1/5 insert_max_filter_ratio is 0.100000. shows the failure reason.
  • The URL at the end identifies diagnostic data. It may be private in a managed warehouse. See View error rows.

Best practices​

Data volume​

Use INSERT INTO VALUES for small application writes, tests, and sample data. For large-batch write requirements, evaluate Group Commit or other batch load methods.

View error rows​

When the INSERT INTO result provides a url field, use the following command to view the error rows:

SHOW LOAD WARNINGS ON "url";

Example:

mysql> SHOW LOAD WARNINGS ON "<error-log-url>"\G
*************************** 1. row ***************************
JobId: -1
Label: NULL
ErrorMsgDetail: Reason: column_name[user_id], null value for not null column, type=BIGINT. src line [];
1 row in set (0.00 sec)

Common causes of errors include:

  • The source column length exceeds the target column length.
  • Column types do not match.
  • Partitions do not match.
  • Column order does not match.

Use the session variable enable_insert_strict to control whether INSERT INTO rejects rows that fail data-quality checks. When strict mode is disabled, insert_max_filter_ratio also controls whether the insert can commit.

FAQ​

Q1: Is INSERT INTO VALUES synchronous or asynchronous?

A: For the ordinary synchronous inserts described here, the statement returns the load result directly. If the returned status is COMMITTED, use SHOW TRANSACTION to check when the data becomes visible. Group Commit can change acknowledgment and visibility behavior.

Q2: Does INSERT INTO VALUES guarantee atomicity?

A: Yes. All accepted rows in one ordinary synchronous insert commit atomically. Configured filtering can reject rows before commit, so verify the affected and filtered row counts.

Q3: Does a returned status of COMMITTED mean the load failed?

A: No. COMMITTED indicates that the load is complete and the data will become visible shortly, with no retry required. Use SHOW TRANSACTION to check TransactionStatus until it becomes VISIBLE.

Q4: Why does the load report Insert has too many filtered data?

A: When enable_insert_strict=false, the proportion of filtered data exceeded the threshold set by insert_max_filter_ratio. Either relax insert_max_filter_ratio, or check whether the source data conforms to the table schema (column types, NULL allowance, and so on).

Q5: What method should be used for large-batch loading?

A: INSERT INTO VALUES is limited by the commit bottleneck under high concurrency or large data volumes. Enable Group Commit, or choose dedicated load methods such as Stream Load or Broker Load.

Troubleshooting​

SymptomPossible causeSolution
Error null value for not null columnA NULL value was inserted into a NOT NULL column.Fix the source data, or change the target column to allow NULL.
Error Insert has too many filtered dataThe proportion of filtered rows exceeds insert_max_filter_ratio.Increase the insert_max_filter_ratio threshold, or fix the source data.
Error Label Already ExistsThe specified label is already in use.Check the existing job or transaction first. If the batch already committed, do not resubmit it. Use a new label only for a distinct batch or a confirmed failed attempt.
The task is canceled after running for a long time without completing.Exceeds insert_load_default_timeout_second or insert_timeout.Check the session's insert_timeout and adjust it if appropriate, or split the load into smaller batches. For service-managed timeout settings, contact VeloDB Cloud support.
Throughput is low under high concurrency.Limited by the bottleneck of the commit phase.Enable Group Commit.

See also​

For detailed syntax, see the INSERT INTO reference. You can also enter HELP INSERT in the MySQL client command line for more help.

Cost and cleanup​

Loading consumes warehouse compute and storage. See Billing. Use a separate test database or table, verify the result, and remove only test objects that you no longer need. Keep the original input data until you have checked the load status and representative target rows.