Export data via TQL

Export data via TQL

The table data is converted to TQL and extracted into a file.

📌
For smooth practice, the following query should be run to prepare tables and data.
CREATE TAG TABLE IF NOT EXISTS EXAMPLE (
    NAME VARCHAR(20) PRIMARY KEY,
    TIME DATETIME BASETIME,
    VALUE DOUBLE SUMMARIZED
);
INSERT INTO EXAMPLE VALUES('TAG0', TO_DATE('2021-08-12'), 100);
INSERT INTO EXAMPLE VALUES('TAG0', TO_DATE('2021-08-13'), 110);

Export CSV

SQL(`select * from example`)
CSV()

Export JSON

SQL(`select * from example`)
JSON()

Export CSV with TQL script

Copy the code below into TQL editor and save export-tql-csv.tql.

SQL( 'select * from example' )
SCRIPT({
    text := import("text")
    ctx := import("context")

    key := ctx.key()
    column := ctx.value()
    value := int(column[1])
    r_value := ""

    if  (value % 2) == 0 {
        r_value = "even"
    } else {
        r_value = "odd"
    }

    ctx.yield(key + "-tql", value,  r_value)
})
CSV()

Open it with web browser at http://127.0.0.1:5654/db/tql/export-tql-csv.tql, or use curl command on the terminal.

TAG1-tql,11,odd
TAG0-tql,10,even
Last updated on