AI tools that generate SQL have a trust problem. They produce queries that look right and often run, but developers have no way to verify the logic buried in layers of nested window functions and subqueries. SQLazy, a new tool from the esProc team, attacks this problem by splitting the workflow in two: AI writes the logic as step-by-step natural language instructions, and a compiler turns those steps into the final SQL.

The core idea: separate logic from syntax

Most AI SQL assistants work by generating the complete query in one shot. You paste a prompt, get back a statement, and hope it does what you asked. When the query involves chained window functions, conditional aggregations, or sessionization logic, the result can be dozens of lines deep and nearly impossible to audit by hand.

SQLazy takes a different path. You describe each transformation as an individual step using semi-natural language. A step might filter rows, sort by a column, group and aggregate, or rank results. Each step reads from the previous one, building a clear pipeline. The compiler then assembles these steps into native SQL for your target database.

The critical distinction: the LLM never touches the final SQL. It helps you decompose a complex requirement into a sequence of simple operations. You review that sequence in plain terms. Then the compiler produces the output, which means no hallucinated syntax, no invented functions, no silent logic errors from a language model.

A concrete example: finding the longest rising streak

Suppose you need to find the longest consecutive period where a stock's closing price kept going up. In standard SQL, this requires a chain of LAG, CASE, SUM OVER, and nested GROUP BY queries, typically four or five levels deep. The generated query below is what SQLazy produces, and it is the kind of SQL that most developers would not volunteer to write or review.

WITH t2 AS (
  SELECT CODE, DT, CL
  FROM stock
  WHERE CODE = 100046
)
SELECT MAX(ContinuousDays) AS max_ContinuousDays
FROM (
  SELECT NoRisingDays, COUNT(DT) AS ContinuousDays
  FROM (
    SELECT CODE, DT, CL,
      SUM(CASE WHEN CL < col__3 THEN 1 ELSE 0 END)
        OVER (ORDER BY DT ASC) + 1 AS NoRisingDays
    FROM (
      SELECT t2.*, LAG(CL) OVER (ORDER BY DT ASC) AS col__3
      FROM t2
    ) sub__4
  ) t3
  GROUP BY NoRisingDays
) t4

The SQLazy workflow that produces this query is five lines in a table. Each row does one thing: filter to a single stock code, sort ascending, segment by price drops, count consecutive days per segment, and take the maximum. The logic is readable without any SQL syntax at all.

Step-by-step debugging and cross-database output

SQLazy includes a debugger that executes each workflow step independently and shows intermediate results. Instead of guessing which subquery went wrong, you inspect the output of every transformation. This is useful during development and equally useful for teaching, since it makes window function behavior visible rather than abstract.

The same workflow compiles to different SQL dialects. The tool currently supports MySQL, PostgreSQL, Oracle, Snowflake, BigQuery, MS SQL Server, DuckDB, Hive, SparkSQL, ClickHouse, DAMENG, OceanBase, PolarDB, and several others. Write the logic once, generate for any of these targets. No more maintaining separate versions of the same analytical query for different platforms.

Two ways to use it: web app and desktop IDE

The web app at sqlazy.com requires no signup and runs in the browser. It handles uploaded sample data and provides limited compute for free. The desktop IDE runs locally and supports larger datasets, bring-your-own LLM keys, and unlimited debugging. The desktop version can also generate SPL code, an alternative representation for extremely complex scenarios. Both share the same core compiler.

For teams with sensitive data, the commercial edition of the desktop IDE supports fully offline operation and private deployment. The free edition requires an online license check at startup but otherwise runs locally.

What SQLazy does not do

SQLazy is a query design tool, not a runtime engine. The output is plain SQL text that you paste into whatever database or BI tool you already use. There is no deployment step, no integration layer, no proprietary runtime to manage. The compiler handles basic logical optimizations like merging steps and collapsing unnecessary CTE layers, but advanced performance tuning is left to your database's query optimizer. Recursive queries are not yet supported, though they appear on the roadmap.

A library of real-world examples

The repository ships with examples organized by analytics pattern: consecutive trend detection, event sessionization, conditional grouping, time-window calculations, data cleaning, dynamic reporting, financial analysis, behavioral analytics, and advanced aggregation techniques. Each example shows the natural language workflow alongside the compiled SQL, giving developers a reference for patterns that are notoriously difficult to get right in raw SQL.

The examples and documentation are MIT licensed. The SQLazy application itself is proprietary, though the web app and personal use of the desktop IDE are free.

SQLazy sits in an interesting spot between two common frustrations. AI SQL tools are fast but opaque. Hand-written analytical SQL is trustworthy but painful. By letting AI handle the decomposition work and a compiler handle the final output, SQLazy tries to give developers both speed and confidence without forcing a choice between them.