Zum Inhalt springen
POST AI agent ready /v1/sql/parse

SQL Parse API - Extract Tables, Columns, and Clauses

Detects query type (SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP), extracts table names from FROM/JOIN/INTO/UPDATE clauses, extracts columns from the SELECT list (resolving AS aliases), and reports boolean flags for WHERE, JOIN, and subquery presence.

Parameters

stringrequired

SQL query to inspect.

Code examples

curl -X POST https://api.botoi.com/v1/sql/parse \
  -H "Content-Type: application/json" \
  -d '{"sql":"SELECT u.id, u.email FROM users u JOIN accounts a ON a.user_id = u.id WHERE u.active = TRUE"}'

When to use this API

Auto-generate permission checks

Before running a user-supplied query, parse it and verify every referenced table is in the user's allowed list. Block queries that touch restricted tables without running them.

Query impact analysis

When refactoring a database, parse every query in your codebase and grep for a table being renamed. Lists every call site to update.

Classify queries for metrics

Aggregate slow-query logs by type (SELECT vs INSERT) and table. Quickly identify whether a performance issue sits in reads or writes and which tables dominate.

Frequently asked questions

What query types are recognized?
SELECT, INSERT, UPDATE, DELETE, CREATE (TABLE), ALTER (TABLE), DROP. Anything else returns type:"UNKNOWN".
How are aliases handled in columns?
An AS alias is extracted as the column name. "SELECT first_name AS fn" yields "fn" in columns. Without AS, the last token of each select expression is used.
Are schema-qualified tables preserved?
Yes. "public.users" is returned as-is in the tables array. Quoted and backticked names are dequoted for consistency.
Does the parser build a full AST?
No. It is regex-based and pragmatic. Complex queries (CTEs, window functions, deeply nested subqueries) may miss tables or columns. For full AST parsing use a dedicated library.
What does has_subquery mean?
True when the query contains "(SELECT" anywhere, indicating at least one subquery. Useful for flagging queries that might need rewriting for performance.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.