Install
openclaw skills install kwdb-text2sql-aiotConvert natural language queries to KWDB SQL for time series data, relational data and cross-model analysis. Use this skill whenever users ask to query KWDB databases, write SQL for KWDB, or convert natural language to KWDB-specific SQL syntax. Supports: CREATE DATABASE/TABLE, downsampling, interpolation, latest value queries, aggregation analysis, cross-model queries, window/session/event analysis.
openclaw skills install kwdb-text2sql-aiotBased on the user's query, read the appropriate reference file:
| Query Type | Reference File |
|---|---|
| Query routing (start here) | references/scenarios.md |
| MCP integration | references/mcp-integration.md |
| 时序DDL (创建时序库/表) | references/ts-ddl.md |
| 聚合操作及降采样 (每小时/每天统计) | references/ts-downsampling.md |
| 插值/填充缺失值 | references/ts-interpolation.md |
| 最新值查询 | references/ts-latest-value.md |
| 滑动窗口/session/event | references/ts-window-events.md |
| 关系表查询 | references/relational.md |
| 跨模查询(时序表+关系表) | references/cross-model.md |
| 时序函数语法速查 | references/ts-functions.md |
| 关系函数语法速查 | references/relational-functions.md |
| NL Pattern | SQL Pattern |
|---|---|
| 最近N分钟/小时/天的数据 | WHERE ts >= NOW() - INTERVAL 'N hour' |
| 每小时/每天的平均值 | time_bucket(ts, '1h/1d') + avg(col) |
| 每N分钟/小时/天降采样 | time_bucket(ts, 'X') + aggregation |
| 填充缺失值 | time_bucket_gapfill() + interpolate() |
| 最新数据 | last(col) or ORDER BY ts DESC LIMIT 1 |
| 滑动窗口 | TIME_WINDOW(ts, '1h', '15m') |
| 关联设备信息 | JOIN devices ON ... |
Detect MCP availability: Call read-query with SELECT 1
Get database name (if not provided by user):
SHOW DATABASES to list all databasesDiscover tables in database: Execute SHOW TABLES FROM {database_name}
Identify candidate tables:
Get table schema: Execute SHOW CREATE TABLE {database_name}.{table_name}, do not use DESCRIBE
Proceed to Phase 1 with verified schema
When MCP is unavailable:
Option A - Ask user: "请提供表结构信息(表名、列名)"
Option B - Use assumed fields: "我将使用常见字段名生成 SQL,请验证"
Proceed to Phase 1
references/scenarios.md - single entry point with decision treets-downsampling.mdts-interpolation.mdts-latest-value.mdts-window-events.mdcross-model.mdrelational.mdts-functions.md (time-series) or relational-functions.md (relational)assets/output-template.mdPrerequisite: SQL has been generated in Phase 2 and formatted in Phase 3.
Note: If MCP was successfully used in Phase 0 and schema was discovered, MCP is available. If Phase 0 indicated MCP was unavailable, skip this phase entirely.
If MCP availability is unknown (e.g., Phase 0 was skipped), verify now:
read-query with SELECT 1Prompt user:
生成的 SQL 已准备就绪。是否需要通过 kwdb-mcp-server 执行该 SQL?
- 输入 "是" 或 "执行" → 继续执行
- 输入 "否" 或 "跳过" → 结束,不再执行
If user declines → end workflow.
Analyze the generated SQL:
read-querywrite-queryCall the appropriate MCP tool:
For read queries (read-query):
{
"sql": "<generated SQL>"
}
For write queries (write-query):
{
"sql": "<generated SQL>"
}
On Success: Report to user:
## Execution Result
- Status: success
- Query Type: read / write
- Row Count: N
- Auto-Limited: true/false
### Results
[formatted table if applicable]
On Failure:
## Execution Result
- Status: failed
- Error: [error message]
- Analysis: [cause analysis]
references/scenarios.md - Query routing entry point (decision tree)references/mcp-integration.md - How to use kwdb-mcp-server for schema discoveryreferences/ts-ddl.md - Time series DDL (CREATE DATABASE/TABLE with TAGS)references/ts-downsampling.md - time_bucket for fixed-interval downsamplingreferences/ts-interpolation.md - time_bucket_gapfill + interpolate for gap fillingreferences/ts-latest-value.md - first/last/last_row for latest value queriesreferences/ts-window-events.md - TIME_WINDOW, SESSION_WINDOW, EVENT_WINDOW, TWA, diffreferences/relational.md - Standard SQL for relational tablesreferences/cross-model.md - JOIN between relational and time seriesreferences/ts-functions.md - KWDB time-series function syntax referencereferences/relational-functions.md - KWDB relational function syntax referenceThis Error Type table is used by:
When a user reports that generated SQL failed, diagnose and regenerate:
| Error Type | Likely Cause | Fix |
|---|---|---|
relation "xxx" does not exist | Wrong table name | Ask user to confirm table name, re-discover via MCP |
column "xxx" not found | Wrong column name | Use MCP to re-read schema, update field mapping |
syntax error | SQL syntax issue | Review KWDB SQL syntax, check function parameter order |
invalid interval | Wrong interval format | Use format like '1h', '1d', '5m' — not复合格式 like '1d1h' |
| Overflow / out of range | Aggregation result too large | Add filters to reduce result set size |
ambiguous column reference | Column name exists in both joined tables | Use fully-qualified column names (table.column) |
permission denied | No write permission | Report to user, do not regenerate |
duplicate key | Constraint violation | Report to user, do not regenerate |
When SQL fails:
ts-functions.md or relational-functions.md and relevant reference fileUse read-query tool to execute SHOW commands:
| SQL Command | Purpose |
|---|---|
SHOW DATABASES | List all databases |
SHOW TABLES FROM {database_name} | List all tables in a database |
SHOW CREATE TABLE {database_name}.{table_name} | Get table structure (columns, types, tags, comments) |