agentCLAWHUBUnverified

KWDB Text2SQL AIoT

Convert 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

Rank

62

Safety

84

Downloads

1.2k

Updated

Oct 11, 2026

Version

1.2.1

Source

CLAWHUB

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.2K downloads reported by the source. Last updated 10/11/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Public facts

Every fact links back to the source it came from.

Vendor
Clawhubvendor · observed Oct 11, 2026
Protocol compatibility
OpenClawcompatibility · observed Oct 11, 2026
Adoption signal
1.2K downloadsadoption · observed Oct 11, 2026
Latest release
1.2.1release · observed Aug 28, 2026
Handshake status
UNKNOWNsecurity

Install and run

Setup complexity: low.

clawhub skill install s17e2f9k2hwm2p7q50y9wz03fs8445dh:kwdb-text2sql-aiot
  1. Install using `clawhub skill install s17e2f9k2hwm2p7q50y9wz03fs8445dh:kwdb-text2sql-aiot` in an isolated environment before connecting it to live workloads.
  2. No published capability contract is available yet, so validate auth and request/response behavior manually.
  3. Review the upstream CLAWHUB listing at https://clawhub.ai/kwdb/kwdb-text2sql-aiot before using production credentials.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-kwdb-kwdb-text2sql-aiot/snapshot"

Documentation

CLAWHUB

145,840 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: kwdb-text2sql-aiot
description: |
  Convert 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.
triggers:
  - query KWDB database
  - write SQL for KWDB
  - convert natural language to SQL
  - time series query
  - IoT sensor data query
  - downsampling query
  - interpolation query
  - latest value query
  - cross-model join query
  - 创建库/创建表/CREATE DATABASE/CREATE TABLE
  - 时序/降采样/插值/最新值/跨模
---

# KWDB Text-to-SQL Skill

## Query Type Routing

Based 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` |

## Quick Reference

| 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 ...` |

## Workflow

### Phase 0: MCP Detection & Schema Discovery (Recommended)

1. **Detect MCP availability**: Call `read-query` with `SELECT 1`
   - If successful → MCP is available
   - If failed → MCP is unavailable, proceed to fallback

2. **Get database name** (if not provided by user):
   - Ask user: "请提供要查询的数据库名称"
   - Or execute `SHOW DATABASES` to list all databases

3. **Discover tables in database**: Execute `SHOW TABLES FROM {database_name}`

4. **Identify candidate tables**:
   - Match NL keywords to table names (e.g., "传感器" → sensor_data)
   - If multiple candidates → ask user: "请确认表名: [A, B, C]?"

5. **Get table schema**: Execute `SHOW CREATE TABLE {database_name}.{table_name}`, do not use `DESCRIBE`
   - Note column names, types, primary key, tags, comments
   - Map NL field names to actual column names

6. **Proceed to Phase 1** with verified schema

### Phase 0 Fallback: No MCP Available

When MCP is unavailable:

1. **Option A - Ask user**: "请提供表结构信息(表名、列名)"
   - Wait for user to describe the schema
   - Proceed to Phase 1

2. **Option B - Use 

_meta.json

{
  "ownerId": "kn7fr8q8f22jd6gzb6f7prf9g183z64v",
  "slug": "kwdb-text2sql-aiot",
  "version": "1.2.1",
  "publishedAt": 1787878044722
}

references/cross-model.md

# Cross-Model Query Reference

Queries that join relational and time-series tables in KWDB.

## KWDB Multi-Model Architecture

- **Relational Tables**: Standard SQL tables with primary keys
- **Time-Series Tables**: Tables with timestamp and tag columns
- **Cross-Model Queries**: JOIN between relational and time-series tables

## Join Types Supported

| Join Type | Keyword | Description |
|-----------|---------|-------------|
| Inner Join | `INNER JOIN` or `JOIN` | Only matching rows |
| Left Join | `LEFT JOIN` | All left + matching right |
| Right Join | `RIGHT JOIN` | Matching left + all right |
| Full Join | `FULL JOIN` | All rows from both tables |

### FULL JOIN Constraint

When using `FULL JOIN`, **avoid subqueries in the join condition**:

```sql
-- Avoid (may cause issues):
SELECT * FROM a FULL JOIN (SELECT ... FROM b WHERE ...) AS sub ON a.id = sub.id

-- Prefer:
SELECT * FROM a FULL JOIN b ON a.id = b.id
```

## Unsupported Joins

- Cross Join (Cartesian product)

## Subqueries Supported

KWDB supports the following subquery types in cross-model queries:
- **Correlated subquery**: Inner query depends on outer query results
- **Non-correlated subquery**: Inner query runs independently, executes once
- **Correlated scalar subquery**: Returns a single value based on outer query
- **Non-correlated scalar subquery**: Independent, returns single value
- **FROM subquery**: Full SQL query nested in FROM clause as a temp table

## Common Patterns

### Join on Primary Tag

Time-series tables typically join on their primary tag:

```sql
relational_table.id = timeseries_table.primary_tag
```

### Example: Device Info with Latest Readings

```sql
-- Input: "Get device names with their latest temperature readings"
SELECT
    d.device_name,
    d.location,
    t.latest_temp,
    t.ts AS reading_time
FROM devices d
INNER JOIN (
    SELECT
        device_id,
        last(temperature) AS latest_temp,
        last(ts) AS ts
    FROM sensor_data
    GROUP BY device_id
) t ON d.device_id = t.device_id;
```

### Example: Product Catalog with Sales Statistics

```sql
-- Input: "Show product details with total sales in the last month"
SELECT
    p.product_id,
    p.product_name,
    p.category,
    COALESCE(s.total_quantity, 0) AS total_sold,
    COALESCE(s.total_revenue, 0) AS total_revenue
FROM products p
LEFT JOIN (
    SELECT
        product_id,
        sum(quantity) AS total_quantity,
        sum(quantity * price) AS total_revenue
    FROM sales
    WHERE sale_date >= NOW() - INTERVAL '1 month'
    GROUP BY product_id
) s ON p.product_id = s.product_id
ORDER BY total_revenue DESC;
```

### Example: Location-Based Aggregation

```sql
-- Input: "Calculate average temperature per location"
SELECT
    d.location,
    avg(t.temperature) AS avg_temp,
    count(*) AS reading_count
FROM locations d
INNER JOIN sensor_data t ON d.device_id = t.device_id
WHERE t.ts >= NOW() - INTERVAL '24 hours'
GROUP BY d.location
ORDER BY avg_temp DESC;
```

### Example: Real-Time

references/mcp-integration.md

# KWDB MCP Server Integration

This guide describes how to use kwdb-mcp-server to automatically discover database schema and generate accurate SQL from natural language.

## MCP Tools

### read-query

Executes read-only SQL queries (SELECT, SHOW, EXPLAIN).

**Parameters:**
- `sql` (required) - The SQL query to execute

**Returns:**
```json
{
  "status": "success",
  "type": "query_result",
  "data": {
    "result_type": "table",
    "columns": ["col1", "col2"],
    "rows": [{"col1": "val1", "col2": "val2"}],
    "metadata": {
      "row_count": 1,
      "query": "SELECT ...",
      "auto_limited": false
    }
  }
}
```

**Note:** SELECT queries without LIMIT automatically get `LIMIT 20` added to prevent large result sets. Check `metadata.auto_limited` to detect this.

## Schema Discovery via SHOW Commands

Use `read-query` tool to execute SHOW commands for schema discovery:

| 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 complete table structure |



## Workflow: Schema-Aware SQL Generation

### Step 1: Detect MCP Availability

Call `read-query` with `SELECT 1` to verify MCP is available.

### Step 2: Get Database Name (if not provided)

Ask user which database to query, or execute `SHOW DATABASES` to list all databases.

### Step 3: Discover Tables

Execute `SHOW TABLES FROM {database_name}` to get all tables in the database.

### Step 4: Match Candidate Tables

Based on natural language keywords, identify candidate tables:
- "设备" / "device" / "传感器" / "sensor" → tables with device/sensor in name
- "温度" / "temperature" → tables with temperature-related columns
- "历史" / "history" → time-series tables

If multiple tables match, ask the user to confirm.

### Step 5: Get Table Schema

For each candidate table, execute `SHOW CREATE TABLE {database_name}.{table_name}` to get column definitions.

### Step 6: Map NL to Schema

Map natural language field references to actual column names:
- "时间" / "timestamp" → ts column
- "设备ID" / "device_id" → tag columns
- "温度" / "temperature" → measurement columns

### Step 7: Generate SQL

Use the schema information to construct accurate SQL.

## Example

**User query:** "查询最近24小时每台设备的平均温度"

**MCP-assisted workflow:**

1. Ask user for database name → "iot_db"

2. Execute `SHOW DATABASES` to verify database exists

3. Execute `SHOW TABLES FROM iot_db` → returns: ["devices", "sensor_data", "alarms"]

4. Identify candidate tables: "sensor_data" likely contains temperature readings

5. Execute `SHOW CREATE TABLE iot_db.sensor_data`:
```sql
CREATE TABLE iot_db.sensor_data (
    ts TIMESTAMPTZ NOT NULL,
    temperature DOUBLE,
    humidity DOUBLE,
    device_id INT4
) TAGS (
    device_id INT4 NOT NULL,
    location VARCHAR(100)
) PRIMARY TAGS (device_id)
```

6. Execute `SHOW CREATE TABLE iot_db.devices`:
```sql
CREATE TABLE iot_db.devices (
    devi

references/relational-functions.md

# KWDB Relational Functions Reference

Relational database functions for KWDB, following CockroachDB SQL dialect.

## Conditional Functions

- `COALESCE(val, ...)` - returns first non-NULL value
- `IF(cond, then, else)` - conditional evaluation
- `IFNULL(val, else)` - alias for COALESCE with two operands
- `NULLIF(val1, val2)` - returns NULL if val1 equals val2, else val1
- `CASE WHEN cond THEN val ... [ELSE val] END` - case expression

## Comparison Functions

- `between(val, low, high)` - val between low and high (inclusive)
- `greatest(val, ...)` - maximum value from list
- `least(val, ...)` - minimum value from list

## Type Casting

- `CAST(val AS type)` - cast value to type
- `type::type` - PostgreSQL-style cast notation (e.g., `col::INT`)

## Math Functions

- `abs(val)` - absolute value
- `avg(val)` - average (aggregate)
- `ceil(val)` / `ceiling(val)` - round up
- `cbrt(val)` - cube root
- `div(val, divisor)` - integer division
- `exp(val)` - e to the power of val
- `floor(val)` - round down
- `ln(val)` - natural logarithm
- `log(val)` / `log(val, base)` - logarithm (base 10 if single arg)
- `log2(val)` - logarithm base 2
- `log10(val)` - logarithm base 10
- `max(val)` - maximum (aggregate)
- `min(val)` - minimum (aggregate)
- `mod(val, divisor)` - modulo remainder
- `pi()` - pi constant (3.14159...)
- `power(val, exp)` / `pow(val, exp)` - val raised to power
- `random()` - random value between 0 and 1
- `round(val)` - round to nearest integer
- `setseed(val)` - set random seed
- `sign(val)` - sign of value (-1, 0, 1)
- `sqrt(val)` - square root
- `sum(val)` - sum (aggregate)
- `trunc(val)` - truncate decimal part

## Trigonometric Functions

- `acos(val)` - arc cosine
- `asin(val)` - arc sine
- `atan(val)` - arc tangent
- `atan2(y, x)` - arc tangent of y/x
- `cos(val)` - cosine
- `cot(val)` - cotangent
- `degrees(val)` - radians to degrees
- `radians(val)` - degrees to radians
- `sin(val)` - sine
- `tan(val)` - tangent

## Hyperbolic Functions

- `sinh(val)` - hyperbolic sine
- `cosh(val)` - hyperbolic cosine
- `tanh(val)` - hyperbolic tangent
- `arcsinh(val)` - inverse hyperbolic sine
- `arccosh(val)` - inverse hyperbolic cosine
- `arctanh(val)` - inverse hyperbolic tangent

## String Functions

- `char_length(val)` / `character_length(val)` - character count
- `concat(val, ...)` - concatenate values
- `concat_ws(sep, val, ...)` - concatenate with separator
- `initcap(string)` - capitalize first letter of each word
- `length(string)` - character length
- `lower(string)` - convert to lowercase
- `lpad(string, length)` / `lpad(string, length, fill)` - pad left
- `octet_length(val)` - byte length
- `bit_length(val)` - bit length
- `replace(string, from, to)` - replace substring
- `reverse(string)` - reverse string
- `rpad(string, length)` / `rpad(string, length, fill)` - pad right
- `left(string, n)` - first n characters
- `right(string, n)` - last n characters
- `rtrim(string)` / `rtrim(string, chars)` - trim right
- `ltrim(string)` / `lt
Github ReposUpdated 1d agoRank 70

AionUi

Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!

MCPOPENCLAW
Github ReposUpdated 6mo agoRank 70

activepieces

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

OPENCLAW
Github ReposUpdated 6mo agoRank 70

cherry-studio

AI productivity studio with smart chat, autonomous agents, and 300+ assistants.

MCPOPENCLAW
Github ReposUpdated 7mo agoRank 70

CopilotKit

The Frontend for Agents & Generative UI. React + Angular

OPENCLAW

Machine-readable data

The same record, as JSON, for agents and crawlers.

{
  "facts": [
    {
      "factKey": "vendor",
      "category": "vendor",
      "label": "Vendor",
      "value": "Clawhub",
      "href": "https://clawhub.ai/kwdb/skills/kwdb-text2sql-aiot",
      "sourceUrl": "https://clawhub.ai/kwdb/skills/kwdb-text2sql-aiot",
      "sourceType": "profile",
      "confidence": "medium",
      "observedAt": "2026-10-11T01:57:15.025Z",
      "isPublic": true
    },
    {
      "factKey": "protocols",
      "category": "compatibility",
      "label": "Protocol compatibility",
      "value": "OpenClaw",
      "href": "https://www.xpersona.co/api/v1/agents/clawhub-kwdb-kwdb-text2sql-aiot/contract",
      "sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-kwdb-kwdb-text2sql-aiot/contract",
      "sourceType": "contract",
      "confidence": "medium",
      "observedAt": "2026-10-11T01:57:15.025Z",
      "isPublic": true
    },
    {
      "factKey": "traction",
      "category": "adoption",
      "label": "Adoption signal",
      "value": "1.2K downloads",
      "href": "https://clawhub.ai/kwdb/kwdb-text2sql-aiot",
      "sourceUrl": "https://clawhub.ai/kwdb/kwdb-text2sql-aiot",
      "sourceType": "profile",
      "confidence": "medium",
      "observedAt": "2026-10-11T01:57:15.025Z",
      "isPublic": true
    },
    {
      "factKey": "latest_release",
      "category": "release",
      "label": "Latest release",
      "value": "1.2.1",
      "href": "https://clawhub.ai/kwdb/kwdb-text2sql-aiot",
      "sourceUrl": "https://clawhub.ai/kwdb/kwdb-text2sql-aiot",
      "sourceType": "release",
      "confidence": "medium",
      "observedAt": "2026-08-28T00:47:24.722Z",
      "isPublic": true
    },
    {
      "factKey": "handshake_status",
      "category": "security",
      "label": "Handshake status",
      "value": "UNKNOWN",
      "href": "https://www.xpersona.co/api/v1/agents/clawhub-kwdb-kwdb-text2sql-aiot/trust",
      "sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-kwdb-kwdb-text2sql-aiot/trust",
      "sourceType": "trust",
      "confidence": "medium",
      "observedAt": null,
      "isPublic": true
    }
  ],
  "events": [
    {
      "eventType": "release",
      "title": "Release 1.2.1",
      "description": "- Removed the informational file skill-card.md from the project. - No changes were made to the core skill logic or user-facing functionality.",
      "href": "https://clawhub.ai/kwdb/kwdb-text2sql-aiot",
      "sourceUrl": "https://clawhub.ai/kwdb/kwdb-text2sql-aiot",
      "sourceType": "release",
      "confidence": "medium",
      "observedAt": "2026-08-28T00:47:24.722Z",
      "isPublic": true
    }
  ]
}

Record generated Oct 11, 2026.

Sponsored

Ads related to KWDB Text2SQL AIoT and adjacent AI workflows.