Custom SQL: from writing to execution
This page explains how to have an Agent turn a business query into platform-hosted custom SQL. You don't assemble create, validate, push, or execute commands by hand — focus on stating the business problem, parameters, returned fields, and acceptance criteria.
Tasks to hand to the Agent
- Design a query SQL for a business question.
- Check the datasets, table relations, and field semantics the SQL touches.
- Save a stable query as platform-hosted SQL.
- Modify an existing SQL, validating parameters and results.
- Test-run with sample parameters to confirm the results match expectations.
Prerequisites
- Have the Agent map out the related datasets and table relations first — never write fields from memory.
- Prepare the query goal, filter conditions, sort rules, and expected return fields.
- When live resources are involved, require the Agent to validate and preview before saving or updating.
Common prompts
Design a business query
请帮我设计一条自定义 SQL,用来查询「近 90 天有成交但 30 天未跟进的客户」。
入参包括「负责人、客户等级、最近成交时间范围」。
返回字段需要包含「客户名称、负责人、最近成交金额、最近成交时间、最近跟进时间、未跟进天数」。
请先检查相关数据集和表关系,再给出 SQL 方案和字段来源说明。The AI may call: rabetbase dataset list, rabetbase dataset detail, rabetbase dataset links, rabetbase sql validate.
Validate an existing SQL
请帮我校验这条 SQL 是否适合保存到平台。
重点检查:是否只读、参数是否完整、字段和表名是否来自正确的数据集、是否有高风险语句。
如果有问题,请先说明原因和修正方案,不要直接保存。The AI may call: rabetbase sql validate, rabetbase dataset detail.
Create platform-hosted SQL
请把「客户活跃度统计」保存成平台托管 SQL。
用途是:客户列表页顶部展示高价值客户、沉默客户和待跟进客户数量。
参数是:负责人、客户等级、统计时间范围。
保存前先校验,保存后告诉我 SQL 标识、本地文件位置和试跑方式。The AI may call: rabetbase sql validate, rabetbase sql create, rabetbase sql push, rabetbase sql exec.
Modify an existing SQL
请修改「客户活跃度统计」,增加「客户来源」筛选条件和「最近跟进人」返回字段。
请先拉取当前定义,说明本次会改哪些内容。
修改后校验并用示例参数试跑,最后给出修改前后差异。The AI may call: rabetbase sql pull, rabetbase sql validate, rabetbase sql push, rabetbase sql exec.
Test-run and explain the results
请用以下示例参数试跑「客户活跃度统计」:负责人是张三,客户等级是 A,时间范围是最近 90 天。
请解释返回结果里每个字段的业务含义。
如果结果为空或异常,请判断是参数问题、数据问题还是 SQL 条件问题。The AI may call: rabetbase sql detail, rabetbase sql exec.
What to add to your prompt
- Business question: orders by customer, monthly revenue, abnormal tickets, and so on.
- Input parameters: keywords, time ranges, status, pagination, etc.
- Return fields: the fields the page or API actually needs to show.
- Safety requirements: read-only queries, validate first, preview first, don't blindly overwrite old SQL.
Completion checks
- The datasets, tables, and field sources behind the SQL are explained.
- Parameter definitions are complete, and sample parameters can test-run.
- Risks were validated before saving or modifying.
- The results are explainable in business terms, and the frontend or BFF can call the SQL.
Next step: to use the SQL in the frontend or in BFF, continue with "Code generation and menus" or "BFF scripts: local and remote in sync".