query

mcp_ohmy_sql.sa.query.format_result(result: CursorResult | Result) str[source]

Format SQL query result into a Markdown table.

Note

Markdown tables are the optimal format for presenting SQL query results to LLMs, offering the best combination of token efficiency, comprehension, and maintainability.

  • Token Efficiency: Uses 24% fewer tokens than JSON, reducing API costs

    and fitting more data within context limits

  • Natural LLM Comprehension: Aligns with LLM training data patterns,

    enabling better understanding compared to nested JSON/XML structures

  • Balanced Readability: Maintains both machine parsability and human readability

    for seamless debugging and maintenance

mcp_ohmy_sql.sa.query.ensure_valid_select_query(query: str)[source]

Ensure the query is a valid SELECT statement.

mcp_ohmy_sql.sa.query.execute_count_query(engine: Engine, query: str, params: dict[str, Any] | None = None) int[source]

Executes a SQL SELECT query and returns the count of rows.

TODO: this function is used in query optimizer, we are not using it yet.

mcp_ohmy_sql.sa.query.execute_select_query(engine: Engine, query: str, params: dict[str, Any] | None = None) str[source]

Executes a SQL SELECT query and returns the result formatted as a Markdown table.