CREATE STREAM IF NOT EXISTS devices_db.stream_status_change
INTO devices_db.status_change_log
AS
SELECT
_wstart AS ts,
_wend AS end_ts,
_wduration AS duration_ms,
status,
dev_id,
shift
FROM devices_db.status_sensors
PARTITION BY tbname, dev_id, shift
STATE_WINDOW(status); 执行不了。 下面是背景 :
CREATE STREAM IF NOT EXISTS stream_status_change
INTO devices_db.status_change_log
tags(dev_id binary(32))
AS
SELECT
_wstart AS ts,
_wend AS end_ts,
_wduration AS duration_ms,
status,
shift
FROM devices_db.status_sensors
PARTITION BY tbname, dev_id, shift
STATE_WINDOW(status);
把我提前创建的devices_db.status_change_log删了 ,CREATE STREAM IF NOT EXISTS stream_status_change
INTO devices_db.status_change_log
tags(dev_id binary(32))
AS
SELECT
_wstart AS ts,
_wend AS end_ts,
_wduration AS duration_ms,
status,
shift
FROM devices_db.status_sensors
PARTITION BY tbname, dev_id, shift
STATE_WINDOW(status);
taos> CREATE STREAM IF NOT EXISTS devices_db.stream_status_change
INTO devices_db.status_change_log
tags(dev_id binary(32))
AS
SELECT
_wstart AS ts,
_wend AS end_ts,
_wduration AS duration_ms,
status,
shift
FROM devices_db.status_sensors
PARTITION BY tbname, dev_id, shift
STATE_WINDOW(status);
DB error: syntax error near “into devices_db.status_change_log tags(dev_id binary(32)) as select _wstart as ts, _wend as end_ts, _wduration as duration_ms, status, shift from devices_db.status_sensors partition by tbname, dev_id, shift state_window(status);” [0x80002600] (0.000170s)
taos>
taos> CREATE STREAM IF NOT EXISTS devices_db.stream_status_change
INTO devices_db.status_change_log
tags(dev_id binary(32))
AS
SELECT
_wstart AS ts,
_wend AS end_ts,
_wduration AS duration_ms,
status,
shift
FROM devices_db.status_sensors
PARTITION BY tbname, dev_id, shift
STATE_WINDOW(status);
DB error: syntax error near “into devices_db.status_change_log tags(dev_id binary(32)) as select _wstart as ts, _wend as end_ts, _wduration as duration_ms, status, shift from devices_db.status_sensors partition by tbname, dev_id, shift state_window(status);” [0x80002600] (0.000170s)
taos>
CREATE STREAM IF NOT EXISTS devices_db.stream_status_change STATE_WINDOW(status)
FROM devices_db.status_sensors PARTITION BY tbname, dev_id
INTO devices_db.status_change_log TAGS(dev_id binary(32) as dev_id)
AS
SELECT
_twstart AS ts,
_twend AS end_ts,
_twduration AS duration_ms,
status,
shift
FROM %%tbname
WHERE _c0 >= _twstart and _c0 <= _twend;
这是3.3.6.x版本的写法,3.4版本可以这样写:CREATE STREAM devices_db.stream_status_change
STATE_WINDOW(status)
FROM devices_db.status_sensors
PARTITION BY tbname
INTO devices_db.status_change_log
AS SELECT
_twstart AS ts,
_twend AS end_ts,
_twduration AS duration_ms, status,
shift FROM %%tbname;