# Postgres or MySQL SQL to SQLite and D1

Postgres or MySQL SQL to SQLite and D1 is a tested SKILL.md that converts PostgreSQL or MySQL schema statements, migrations and queries into SQLite that Cloudflare D1 and Turso run, so the converted version behaves like the original and not only parses; an agent buys it once for $0.01 over x402.

- Page: https://aiskills402.com/skills/sql-dialect-to-sqlite
- Category: Code & Engineering (https://aiskills402.com/categories/code)
- Price: $0.01 once, USD-priced, paid in USDC on Base over x402. Price as loaded on this page. The 402 response your agent receives is authoritative.
- Version: 1.0.0
- Card (JSON): https://api.aiskills402.com/v1/skills/sql-dialect-to-sqlite

## Use it when

Converts PostgreSQL or MySQL schema statements, migrations and queries into SQLite that Cloudflare D1 and Turso run, so the converted version behaves like the original and not only parses. Knows the conversions that run without an error and then go wrong - a key written as BIGSERIAL or INT AUTO_INCREMENT that SQLite stores as NULL, a custom enum type or an inline enum that stops checking anything, a default now() or gen_random_uuid() that fails on the first insert, a unique email that was case-insensitive in MySQL, ON UPDATE CURRENT_TIMESTAMP that needs a trigger, a foreign key added later with ALTER TABLE, a schema prefix, DISTINCT ON, ILIKE, double-colon casts, date_trunc, interval arithmetic, DATEDIFF, GROUP_CONCAT with SEPARATOR, MySQL division that keeps the fraction, ON DUPLICATE KEY UPDATE, JSON operators. Answers with the SQLite SQL only, and says CANNOT CONVERT when part of the input has no equivalent in SQLite (a procedural function, row level security, notifications, a stored procedure) instead of dropping it. Use when asked to port, convert or migrate Postgres or MySQL SQL to SQLite, D1 or Turso.

## Not for

Dumps of INSERT rows or COPY blocks (sql-dump-to-sqlite), query tuning, schema design or moving live data. Procedural functions, row level security and notifications get a CANNOT CONVERT line, not SQL. Some D1 rules are owner-measured on 2026-10-08.

## Tested, honestly

Tested 2026-10-09.

- Strong model (claude-sonnet-5-5 (Claude Code alias "sonnet")): Right on all 24, each reply run in SQLite: auto-number keys, an enum turned into a CHECK, a case-insensitive unique email, a pg_dump sequence with a foreign key added later, uuid and jsonb defaults, ILIKE and intervals, date_trunc and extract, MySQL division and DIV, GROUP_CONCAT with a separator, ON DUPLICATE KEY, DISTINCT ON, JSON operators, DATEDIFF and DATE_FORMAT, four refusals with no SQL beside them, and a planted note inside already valid SQLite ignored.
- Weak model (claude-haiku-5-5 (Claude Code alias "haiku")): Right on 23 of 24, each reply run in SQLite, but on the file that was already SQLite it ignored the planted note and then added a sentence about it after the SQL, so the migration would not run.

Note: Twenty-four pieces of PostgreSQL and MySQL written by us, mostly in English and two with Bulgarian text: 14 conversions built around a silent change of meaning (auto-number keys, enums, case-insensitive uniques, pg_dump sequences and late foreign keys, uuid and jsonb defaults, ILIKE, intervals, date functions, integer division, GROUP_CONCAT, upserts, DISTINCT ON, JSON operators), 4 with no SQLite equivalent (dynamic PL/pgSQL, row-level security, pg_notify, a MySQL procedure) and 6 controls, one with a planted note. Each reply is executed in SQLite: a schema is built in an empty database, rows are inserted, rows the original would refuse must be refused, and a query must return the rows the original would return on the same data. The shared request states the format and the one-sentence refusal. No check was widened. One run per model and case.

### With and without the skill

Tested 2026-10-09.

- Conversions right when run (24 cases): Sonnet 24/24 with, 24/24 without; Haiku 23/24 with, 21/24 without.

Same request on both sides, a fence removed first. Sonnet without the skill was already right on all 24, so the skill adds no measured gain for it. Haiku without the skill missed three: it turned MySQL division into SQLite integer division, so 1001 / 2 lost its half, and twice it wrote the table next to the sentence saying a function or trigger could not be converted, while the request asked for no SQL in that case.

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.

Full summary: https://aiskills402.com/skills/sql-dialect-to-sqlite/tests

## Example

### English (claude-sonnet-5-5)

Before:

> SQL to convert: CREATE TABLE users (   id BIGSERIAL PRIMARY KEY,   email VARCHAR(255) NOT NULL UNIQUE,   created_at TIMESTAMPTZ NOT NULL DEFAULT now() );

After:

> CREATE TABLE users (   id INTEGER PRIMARY KEY,   email TEXT NOT NULL UNIQUE,   created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP );

### Bulgarian (claude-sonnet-5-5)

Before:

> SQL to convert: -- Затваря месеца: маркира неплатените фактури като просрочени DELIMITER // CREATE PROCEDURE close_month() BEGIN   DECLARE done INT DEFAULT 0;   DECLARE inv INT;   DECLARE cur CURSOR FOR SELECT id FROM invoices WHERE paid = 0;   DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;   OPEN cur;   read_loop: LOOP     FETCH cur INTO inv;     IF done THEN LEAVE read_loop; END IF;…

After:

> CANNOT CONVERT: процедурата close_month() използва курсор, променливи и цикъл (DECLARE, OPEN, FETCH, LOOP), което SQLite не може да изрази.

## What is in the file

- The answer
- When the answer is CANNOT CONVERT
- Types and keys
- Queries and write statements
- Work in this order
- Short examples

## Languages

Any language

## How to buy

Agent (HTTP):

1. GET https://api.aiskills402.com/v1/skills/sql-dialect-to-sqlite/file without a payment header. The answer is 402 with a PAYMENT-REQUIRED header (x402 v2): exact amount, asset, network, recipient.
2. Sign `accepts[0]` with an x402 client (for example @x402/core + @x402/evm).
3. Repeat the GET with the signature in the PAYMENT-SIGNATURE header. The answer is 200 with the file, its sha256 and a re-download token.

Agent (MCP): https://mcp.aiskills402.com/mcp — free tools search_skills, get_skill, redownload_skill. Buying itself is over HTTP.

Full flow: https://aiskills402.com/docs

## The file

- Version: 1.0.0
- Size: 13.8 KB (14133 bytes)
- SHA-256: 2240ae3fded3e64f8b5e77788a1872646b649d222f07939d384a1fca843ee639
- Updated: 2026-10-09
- New versions are free through your re-download token.

## Versions

### 1.0.0 (2026-10-09)

First draft, self-designed from the batch 4 table row (rank 12): the brief for this skill had not been written when the writer started. Converts Postgres or MySQL schema statements, migrations, queries and write statements to SQLite (D1, Turso); the whole answer is CANNOT CONVERT when any statement has no equivalent (procedural functions and procedures, row level security, notifications), never a half conversion. Fourteen silent-failure traps (BIGSERIAL and INT AUTO_INCREMENT keys, enum types, now() and uuid defaults, case-insensitive unique, ON UPDATE trigger, pg_dump sequences and late foreign keys, ILIKE and interval, date_trunc, MySQL division, GROUP_CONCAT, ON DUPLICATE KEY, DISTINCT ON, JSON operators, DATEDIFF), four refusals, six controls. Facts probed locally on 2026-10-08 (notes/facts-2026-10-08.md). Price (30000 micro) is a placeholder until the baseline run; class B.

## License

Perpetual, non-exclusive; use and modify for yourself incl. paid work; no resale or republishing. Holder: Georgi Kalchev, aiskills402.com. Terms: https://aiskills402.com/docs#license

## FAQ

### Which SQL comes back, and in what shape?

Only SQLite SQL: converted tables, indexes and triggers, or your query or write statement in the wrapper you ask for. A short line comment marks anything removed or changed in meaning. When a single statement cannot be expressed in SQLite, the whole reply is one line starting CANNOT CONVERT that names the statement and the reason, with no partial SQL beside it.

### How can I trust that the converted SQL behaves like the original?

Each test pastes Postgres or MySQL SQL and then executes the reply in SQLite. A schema is built in an empty database, rows are inserted, rows that the original would refuse must be refused, and what is stored is compared. A query runs on small tables and the rows it returns must equal the rows the original would have returned on the same data. Many spellings of a correct conversion pass, such as a window function or a correlated subselect for DISTINCT ON, while a conversion that only parses fails, and so does one that keeps a word SQLite does not know. Refusal cases must contain no SQL at all.

### Which conversions fail without an error message?

An auto-number key that SQLite stores as NULL, a custom enum type that checks nothing, a unique email that was case-insensitive in MySQL, a column that refreshed itself and now needs a trigger, a foreign key added later with ALTER TABLE, MySQL division that kept the fraction, and an upsert that replaces the row instead of adding to it.

### Does it help Claude Sonnet?

One cent, because on our set Sonnet gained nothing. Twenty-four pieces of Postgres and MySQL went to both Claude models, guided by the file and bare, and every reply was run in SQLite. Sonnet got all 24 right unaided. Haiku moved from 21 to 23: bare, it let MySQL division lose its fraction and twice put a table next to its refusal. Our request was long and named the format and the refusal; a shorter request was not tested. Comments in your SQL stay in their own language.

## Related skills

- [SQL Dump to SQLite: MySQL and Postgres Rows, Unchanged](https://aiskills402.com/skills/sql-dump-to-sqlite.md): $0.03 once
- [SQLite Query From a Question for D1](https://aiskills402.com/skills/sqlite-query-from-question.md): $0.03 once
- [D1 Migration Writer: SQLite Migrations That Apply](https://aiskills402.com/skills/d1-migration-writer.md): $0.07 once

## Measurement limits

- Models other than the two named above were not run.
- Each verdict comes from the test run on the date shown; the skill may have changed since (check the version).
- Full test inputs are not published here, only short excerpts of our own text.
- Results on your own texts, languages and domains can differ.

Offer note: Paid in USDC (USD-pegged) over x402 by an AI agent; one-time.
