TDengine
TDengine copied to clipboard
Question: how to create a stream to load data into super table with tags
Question
I have a summary table (with two tags: location and device_id), the source table device_history also have these two tags, I need to summarized the power value for each location + device_id combination, and load it into the dest table.
CREATE STABLE device_total_power (ts TIMESTAMP, total_power BIGINT) TAGS (location INT, device_id INT);
create stream
CREATE STREAM stream_device_total_power
TRIGGER WINDOW_CLOSE
INTO device_total_power SUBTABLE(CONCAT('device_, CAST(device_id AS VARCHAR(12)), '_total_power'))
AS SELECT _wend AS ts, SUM(power) AS total_power
FROM device_history PARTITION BY location, device_id INTERVAL(1d);
When I run the sql above, I got error:
DB error: Illegal number of columns (0.012870s)
Environment
TDEngine version: 3.1.0.3 Server: Ubuntu 22.04