Skip to content

AI in the editor ​

With a provider set up, the query editor toolbar has an AI menu next to Ask.

Generate SQL ​

AI › Generate from prompt…: describe the query (top 10 users by signup date), then Generate or Generate & Run.

Lily sends your request and the schema, then checks the result with EXPLAIN without running it. If the database rejects it, Lily sends the error back to the AI and tries again, up to three times. Writes and DDL are not checked this way, and Lily tells you so.

The generated SQL replaces what is in the editor. Generate & Run then runs it through the normal path: read-only blocking, the :parameter prompt and the write confirmations.

Explain, optimize, fix ​

  • Explain this query describes in plain language what the query does. Only the SQL is sent. (The Explain button in the toolbar is different: it shows the database's plan, with no AI.)
  • Optimize this query sends the SQL and the schema and puts a rewritten query in the editor.
  • Fix with AI, on the error card of a failed query, sends the query, the schema and the error message, and puts the suggested fix in the editor.

Optimize and Fix replace the whole tab, even if you selected part of it. Save anything you want to keep first.

Summarize a result ​

AI › Summarize result sends the column names and up to 50 rows, masked when Lily has scanned for sensitive data, and describes what stands out.

Indexes ​

  • Suggest indexes… looks at your recent reads on this connection (with values replaced by ?) and their plans, and recommends indexes. It only writes text. PostgreSQL, MySQL, SQLite and SQL Server.
  • Speed up this query… proposes one index for the query in the editor, creates it and measures the difference. See EXPLAIN and slow queries.

Document a table ​

In a table tab, Document with AI writes a Markdown description of the table from its columns, types and keys, ready to copy.

Saving queries ​

When you save a query to the library, Lily fills in a title and description for it. You can change them, or click Generate title & description with AI again.

Change with AI ​

Right-click a table in the sidebar and choose Change with AI…. Describe the change:

  • add a deleted_at timestamp for soft-delete
  • add an index on created_at
  • make email unique

Lily sends the table's columns, keys and indexes, a short list of other tables and the business context, and gets back:

  • a summary and any warnings;
  • the Forward DDL;
  • the Rollback DDL, marked Lossy rollback when undoing it would lose data.

Nothing runs. Open forward in editor and Open rollback in editor put the SQL in a query tab, where the usual confirmations apply.

Available on PostgreSQL, MySQL, SQLite, ClickHouse and Trino, on writable connections.

Lily DB is free for personal and commercial use.