The INSERT INTO clause writes query and analysis results to another Logstore within the same project.
Syntax
INSERT INTO target_logstore (key)
SELECT key FROM source_logstore
-
Create an index for the destination fields, such as key, and enable the analysis feature in the destination Logstore.
-
Specify the destination fields after target_logstore. For example,
* | INSERT INTO target_logstore SELECT...is invalid because no destination fields are specified. -
To convert mismatched field data types, use Data type conversion functions in the SELECT statement.
-
Each execution can write up to 10,000 rows.
-
Available in the Chinese mainland only. Not supported in overseas regions.
Parameters
|
Parameter |
Description |
|
target_logstore |
The destination Logstore. Note
Must differ from the source Logstore. |
|
source_logstore |
The source Logstore. |
|
key |
The field or column name. |
Example
The following example counts page views (PVs) per status code in the website_log Logstore and writes the results to test_insert.
Before running this statement, create indexes and enable the analysis feature for the status and PV fields in the test_insert Logstore.
-
Query and analysis statement
* | INSERT INTO test_insert(status,PV) SELECT status, count(*) AS PV FROM website_log GROUP BY status -
Result (source Logstore): A rows: 22 result indicates that 22 rows were inserted into the destination Logstore.
-
Result (destination Logstore): Two records are returned —
status306withPV54, andstatus404withPV27.