Execute Query
kb_queryExecute read-only SQL queries on a KingBase database. Use parameterized queries for safe value substitution with automatic schema qualification.
Instructions
Execute a read-only SQL query (SELECT/WITH/SHOW) against the KingBase database.
Returns query results as a formatted table. Use parameterized queries ($1, $2, ...) for safe value substitution.
Only read-only statements are allowed. For INSERT/UPDATE/DELETE use kb_execute; for DDL use kb_execute_ddl.
š Auto-schema feature: Unqualified table names (without schema prefix) are automatically qualified with the configured schema (DB_SCHEMA env var). You can optionally override this with the 'schema' parameter.
Args:
sql (string): The SELECT query to execute
params (array, optional): Parameter values for $1, $2, ... placeholders
schema (string, optional): Override the default schema for auto-qualifying table names
Returns: Formatted table of query results with row count.
Examples:
sql: "SELECT * FROM biz_cm_attachment LIMIT 5" (auto-qualified with configured schema)
sql: "SELECT * FROM users WHERE status = $1", params: ["active"]
sql: "SELECT * FROM public.sys_user" (explicit schema, not auto-qualified)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SELECT query to execute. Only read-only statements are allowed. | |
| params | No | Optional parameterized query values ($1, $2, ...) | |
| schema | No | Schema name for tables without explicit schema prefix (default: from DB_SCHEMA env or 'public'). When specified, unqualified table names will be automatically prefixed with this schema. |