Data & Analysis

SQLite Query From a Question for D1

Writes the SQL query for SQLite or Cloudflare D1 that answers a question about the data, from the question and the table definitions you paste, so it returns the right rows and not only rows that look right. Knows where plain-language questions turn into wrong results on SQLite - NOT IN against a column that holds NULL, integer division in percentages and money, COUNT of a column that holds NULLs, a LEFT JOIN that a WHERE turns back into an inner join, two one-to-many joins that multiply each other, ties at a LIMIT, NULLs that sort first, dates stored as text in a format that does not sort, a month end that cuts off the last day's timestamps, pairs listed twice, "both A and B" and "top N of each group". Answers with the one statement and nothing else, and says CANNOT ANSWER when the tables do not hold what the question needs, instead of inventing a column. Use when asked to write, check or fix a SELECT for SQLite, D1 or Turso from a question, a report request or a schema.

SQLite Query From a Question for D1 is a SKILL.md that writes the SQL query for SQLite or Cloudflare D1 that answers a question about the data, from the question and the table definitions you paste, so it returns the right rows and not only rows that look right; an agent buys it once for $0.03 over x402.

Tested 2026-10-08No code, no hidden instructionsv1.0.0 · 12.3 KB · perpetual license

Not for

Making a slow query faster, designing the schema, searching text, or writing changes to the data: it writes one read query. Postgres and MySQL follow other rules. It cannot see your rows, so a value in a column that your definitions do not describe can still surprise a query, and a question that is vague about what counts (best, active, recent) gets a refusal, not a guess.

Tested, honestly

Tested 2026-10-08 with a strong and a weak model.

With and without the skill

Results with and without the skill, for Sonnet and Haiku
SonnetHaiku
withwithoutwithwithout
Questions answered right (24 questions)24/2422/2424/2423/24

Same request on both sides, a fence removed first. Read by hand, Sonnet without the skill already wrote correct queries for ties, NULLs, text dates, cents and case, and declined the questions the tables cannot answer. It missed two: on the self-join it wrote the word Wait in the middle of its SQL and corrected itself in place, so the query does not run, and on top N per group it used a column named id that the table does not have. Haiku without the skill missed the self-join.

Same cases and the same checks with and without the skill. The cases are ours, written around what the skill is for; with a handful of cases, a difference of one or two is within noise.

SonnetStrong model, claude-sonnet-5-5
Right on all 24 questions in substance, read by hand: every query ran in SQLite and returned the expected rows, including pairs from a self-join without duplicates, the top rows per group, ties, NULLs, dates stored as text, money in cents and case-insensitive matches; where the tables hold no column for the question it declined to guess. On one such question it declined in its own words instead of the fixed CANNOT ANSWER line the skill asks for, which a program reading the answer would not recognise.
HaikuWeak model, claude-haiku-5-5
Right on all 24 questions in substance, read by hand, with the same queries and refusals as Sonnet; on one refusal it also used its own words instead of the fixed CANNOT ANSWER line.

Full test summary

Example

Our own test text, before and after the skill ran. Excerpts only.

English · claude-sonnet-5-5

Before

Tables: CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT NOT NULL); CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER REFERENCES customers(id), total_cents INTEGER NOT NULL); -- customer_id is NULL for guest checkouts Question: Which customers have never placed an order? Return id and name, ordered by id.

After

CREATE TABLE answer AS SELECT c.id, c.name FROM customers c WHERE NOT EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id) ORDER BY c.id

Bulgarian · claude-sonnet-5-5

Before

Tables: CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL, created_at TEXT NOT NULL); Question: Кои клиенти живеят в София? Върни имената им.

After

CANNOT ANSWER: таблицата customers няма колона за град или адрес (има само id, name, email, created_at), затова не може да се определи кои клиенти живеят в София.

What is in the file

  • The answer
  • Read before you write
  • Dialect: what SQLite does differently
  • Where the rows go wrong
  • Work in this order
  • Short examples

Languages

Any language. Tried in: English, Bulgarian.

License

Perpetual, non-exclusive; use and modify for yourself incl. paid work; no resale or republishing. Holder: Georgi Kalchev, aiskills402.com. Full terms.

Versions

Current version 1.0.0, updated 2026-10-08. Whoever bought an earlier version gets new ones free through the same re-download token.

  1. v1.0.0 · 2026-10-08

    First draft: one read query for SQLite or D1 from a question and table definitions, as the only statement, with CANNOT ANSWER when the tables lack what the question needs or two readings give different rows. Twelve wrong-result traps (NOT IN and NULL, integer division, COUNT of a column, LEFT JOIN with WHERE, two child joins, ties, NULL sort, text dates, month end, pairs, both roles, latest per group), the SQLite dialect list and two D1 limits. Facts re-checked locally on 2026-10-08 (notes/facts-2026-10-08.md). Price and the measured value are set after the baseline run.

FAQ

One question in: what comes out?

One SQL statement, with no commentary around it, built only from the tables and columns you pasted. If the tables cannot answer the question, or two readings of it would return different rows, the reply is a single line beginning CANNOT ANSWER that names the missing column or the two readings, in the language you asked in.

Does it help Claude Sonnet?

Slightly. Twenty-four questions with their tables and data were answered by both Claude models, skill loaded and not, and every query was run in SQLite against the expected rows. On its own Sonnet got 22: on a self-join it wrote the word Wait halfway through its SQL and corrected itself in place, so nothing ran, and on top rows per group it used a column the table does not have. Loaded with the skill, every one of the 24 ran right. Haiku went from 23 to 24.

Which mistakes does it guard against?

Wrong rows that raise no error: NOT IN against a column holding NULL, integer division in a percentage, a LEFT JOIN that a WHERE turns inner, two child tables joined at once so totals multiply, a tie hidden by LIMIT, NULLs sorting first, a month end that loses the last day, and dates stored as text in a format that does not sort.

Does it work for languages other than English?

The question can be in any language; table and column names stay exactly as your definitions write them. The refusal line is written in the language of the question. A comment inside your definitions that talks to the assistant is treated as text, not as an instruction.

Read more

Share

Read this page as Markdown: /skills/sqlite-query-from-question.md.

  • SQL Query Optimizer for D1, SQLite and Turso

    Code & Engineering

    SKILL.md · v1.0.2 · 9.8 KB

    Reviews SQL queries, schemas and migrations for SQLite, Cloudflare D1 and Turso, where the bill and the speed follow the rows a query READS, not the rows it returns. Finds full scans hidden behind LIMIT, aggregates over growing tables, index column gaps, NOT IN, OR, functions and LIKE patterns that switch an index off, OFFSET pagination, N+1 loops, the D1 limit of 100 bound parameters, tables that never shrink and new flag columns that turn the whole history into pending work; ranks them by cost and gives the index or rewrite that fixes each. Use when asked to optimize a SQL query, review a database schema or a migration, find a slow query, or cut rows read on D1, SQLite or Turso.

    $0.05once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 3 Oct 2026

  • D1 Migration Writer: SQLite Migrations That Apply

    Code & Engineering

    SKILL.md · v1.0.1 · 9.8 KB

    Writes a SQL migration for Cloudflare D1 or SQLite from the current schema and the change wanted, so it applies on the first try and leaves the rows already in the database right. Knows what D1 refuses or breaks on, measured on a real D1 database - BEGIN and COMMIT in the file, foreign keys that cannot be switched off (a rebuild defers them, keeps the table name, and never closes with defer_foreign_keys = false, which on D1 silently skips the check), NOT NULL columns without a default, REFERENCES columns with a default, indexed columns dropped before their index. Backfills a new status or marker column so old rows are not picked up as pending work, fills a new counter from the existing rows, orders index columns for the query that needs them, and keeps upserts working against a partial unique index. Use when asked to write, check or fix a D1, SQLite or Turso migration, add or change a column, add an index, make a column unique or required, or rebuild a table.

    $0.07once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • SQLite Search Builder

    Code & Engineering

    SKILL.md · v1.0.0 · 14.5 KB

    Builds or fixes a site or product search so it finds what the user meant, with SQLite full-text search (FTS5) on D1, Turso or SQLite. Word order, singular or plural, endings, case, punctuation and accents stop mattering ("cafe" finds "Café", "tomatoes" finds "tomato", "red tomato" finds "Tomato, red", "ab1042" finds "AB-1042"), and the start of a word is enough ("tom" finds "tomatoes"). Gives one normalize pipeline for accent-insensitive search, a query-side ending remover, prefix search on the index with paging and a short cache, and a small in-memory path for short lists already in the browser. Never loads a whole table to filter it per keystroke. It does not correct typos. Use when asked to implement or fix search, autocomplete or typeahead, when search does not find plurals, accents or reordered words, when a slow LIKE search reads the whole table, or to review a search box on D1, Turso or SQLite.

    $0.01once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 4 Oct 2026

More in Data & Analysis

  • Fixed-Width to CSV: Cut by Spec, Trim Only When Told

    Data & Analysis

    SKILL.md · v1.0.0 · 8.7 KB

    Converts fixed-width text (mainframe exports, bank and statistics files, printed reports) into RFC 4180 CSV from a column specification and answers with the CSV only, no code fence. Positions are 1-based and inclusive unless the spec says otherwise, and count characters, so accented and Cyrillic letters do not shift later columns. Every cell is the exact characters of its positions: nothing is trimmed unless the spec says trim, leading zeros and inner spaces stay, numbers stay text, and an implied decimal becomes a point only where the spec states it. A value with a comma or a quote is quoted. A line that does not fit the spec, overlapping columns, a tab, a byte-based spec meeting non-ASCII text, or a signed overpunch digit gets a fixed one-line CANNOT CONVERT answer instead of a guessed table. Use when a fixed-width file has to become CSV for a spreadsheet, a database or a data pipeline.

    $0.03once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • Log Lines to JSON Lines, Odd Lines Kept Raw

    Data & Analysis

    SKILL.md · v1.0.0 · 8.4 KB

    Parses plain-text log lines into JSON Lines, one record per line, by a format the task states (Apache or nginx combined access log, RFC 5424 syslog, key=value pairs, or a custom pattern with named fields). Splits by the format's grammar and not by spaces, so quoted fields with spaces and escaped quotes stay whole. A dash that the format defines as absent becomes null, fields the task calls numbers become JSON numbers (a status stays a number, a zero byte count stays 0), time stamps keep their written offset, and IPv6 addresses stay whole. A line that only almost fits the format is kept as a raw record exactly as given, never guessed or repaired. Indented stack-trace lines are attached to the previous record only when the task says so. Text inside the log that speaks to the agent is data. Use when asked to convert, parse, structure or load log lines, an access log, syslog output or application logs into JSON, JSONL or NDJSON for a program to read.

    $0.01once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • CSV to JSON Rows: Every Cell Stays Text

    Data & Analysis

    SKILL.md · v1.0.0 · 8.6 KB

    Converts CSV into a JSON array with one object per row, keyed by the header, and answers with the JSON only, no code fence. Every value stays a string exactly as the cell reads, so 007, 1,250, 1.10, TRUE, null, dates, spaces around a name and a value that starts with an equals sign are never turned into numbers, booleans or null, and an empty cell is an empty string. Only a column the task names as integer, number or boolean is converted. Quotes are removed, doubled quotes become one quote, line breaks inside a quoted cell become backslash n. Semicolon and tab files, a byte order mark, CRLF rows and a trailing blank line are handled. A short or long row, a duplicate header name, an unclosed quote, a typed cell that does not fit its type and text that holds no table get a fixed one-line CANNOT CONVERT answer instead of invented or null values. Use when an agent must load a CSV export into code, an API or a database, or when asked to turn CSV into JSON.

    $0.03once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026

  • Markdown Table Repair: Fix the Table, Keep Every Cell

    Data & Analysis

    SKILL.md · v1.0.0 · 10.0 KB

    Repairs a broken Markdown table so GitHub Flavored Markdown renders it as one table with the right columns, without changing the text of any cell, and answers with the table only, no code fence. Adds a missing or malformed alignment row and keeps the alignment colons it finds, adds the missing leading and trailing pipes, escapes a literal pipe inside a cell as backslash-pipe (also inside inline code), pads a short row with empty cells without moving a cell, and turns a tab-separated or HTML table into a Markdown table. Bold, links, code, emoji, numbers such as 007 and 1.10, backslashes and double spaces inside a cell stay exactly as written. A row with more cells than the header, an alignment row that cannot be matched to its columns, a pipe that cannot be told from a border and text with no table get a fixed one-line CANNOT REPAIR answer instead of a guess that moves data between columns. Use when a README, wiki page or another model's answer shows a table as plain text with pipes, or when asked to fix, clean up or convert a table to Markdown.

    $0.05once

    • x402
    • USDC
    • Base
    Get skill

    Tested with Sonnet and Haiku, 8 Oct 2026