All Products
Search
Document Center

Simple Log Service:INSERT INTO clause

Last Updated:Mar 25, 2026

Use the INSERT INTO clause to write the results of SQL queries to another Logstore in the same Project.

Syntax

INSERT INTO target_logstore (key) 
SELECT key FROM source_logstore
Important
  • In the destination Logstore, create an index and enable the analysis feature for the destination field, such as key.

  • Specify the destination fields after target_logstore. For example, * | INSERT INTO target_logstore SELECT... is an invalid statement.

  • If the data types of the source and destination fields do not match, use a data type conversion function in the SELECT statement. For more information, see Data type conversion functions.

  • A single execution can write a maximum of 10,000 rows.

  • This feature is available only in the Chinese mainland.

Parameters

Parameter

Description

target_logstore

The destination Logstore for the query results.

Note

The destination Logstore must be different from the source Logstore.

source_logstore

The source Logstore for the query.

key

The name of the field or column to query and write.

Example

This example calculates the page views (PV) for each status code in a Logstore named website_log and writes the results to a Logstore named test_insert.

Important

Before you run the query, create an index and enable the analysis feature for the status and PV fields in the test_insert Logstore.

  • Query statement

    * | INSERT INTO test_insert(status,PV) SELECT status, count(*) AS PV FROM website_log GROUP BY status
  • Query and analysis result (source Logstore)insert into

  • Query and analysis result (destination Logstore)insert into