aiagent/skill/embedded/builtin/query-datasource/datasources/pgsql.md
pgsqlPOST /api/n9e/db-databases
Authorization: Bearer <token>
Content-Type: application/json
Body: {"cate": "pgsql", "datasource_id": 1, "query": []}
POST /api/n9e/db-tables
Authorization: Bearer <token>
Content-Type: application/json
Body: {"cate": "pgsql", "datasource_id": 1, "query": ["database_name"]}
POST /api/n9e/db-desc-table
Authorization: Bearer <token>
Content-Type: application/json
Body: {"cate": "pgsql", "datasource_id": 1, "query": [{"database": "mydb", "table": "metrics"}]}
POST /api/n9e/ds-query
Authorization: Bearer <token>
Content-Type: application/json
{
"cate": "pgsql",
"datasource_id": 1,
"query": [
{
"sql": "SELECT date_trunc('minute', created_at) AS ts, COUNT(*) AS value FROM events WHERE created_at >= to_timestamp($from) AND created_at < to_timestamp($to) GROUP BY ts ORDER BY ts",
"keys": {
"valueKey": "value",
"labelKey": "",
"timeKey": "ts"
}
}
]
}
| Field | Type | Required | Description |
|---|---|---|---|
sql | string | Yes | SQL query statement, supports $from and $to time variables |
keys.valueKey | string | No | Numeric column name (required for time-series queries); separate multiple with spaces |
keys.labelKey | string | No | Label/grouping column name; separate multiple with spaces |
keys.timeKey | string | No | Time column name |
| Requirement | SQL |
|---|---|
| Count aggregated per minute | SELECT date_trunc('minute', created_at) AS ts, COUNT(*) AS value FROM events WHERE created_at >= to_timestamp($from) AND created_at < to_timestamp($to) GROUP BY ts ORDER BY ts |
| Group statistics by field | SELECT status, COUNT(*) AS value FROM events WHERE created_at >= to_timestamp($from) AND created_at < to_timestamp($to) GROUP BY status |
| Compute percentile | SELECT date_trunc('minute', created_at) AS ts, percentile_cont(0.95) WITHIN GROUP (ORDER BY response_time) AS value FROM requests WHERE created_at >= to_timestamp($from) AND created_at < to_timestamp($to) GROUP BY ts ORDER BY ts |
$from and $to are Unix timestamps (seconds) and must be converted with to_timestamp()date_trunc('minute', col) for time bucketing