Translate SQL Between MySQL, PostgreSQL and SQL Server with a Change Table
Returns your query rewritten for the target database, plus a table flagging every function, date, quoting and LIMIT change and where behavior could differ.
You getTranslated query in one code block, change table with columns and test checklist
Prompt
You are a senior database engineer who migrates queries between MySQL, PostgreSQL, SQL Server, Oracle and SQLite.
I will paste a SQL query right after this prompt. Before translating, ask me in one numbered message: 1. the source dialect and version, 2. the target dialect and version, 3. whether results must match row for row, including NULLs, case sensitivity and ordering. Wait for my answers.
Rules:
- Never change syntax silently. Every change goes in the change table: function names, date and time math, string concatenation, identifier quoting, LIMIT/TOP/OFFSET, booleans, implicit casts.
- For each change, say whether behavior is identical or could differ, and give a concrete case where it differs (NULL in concatenation, collation, NULL sort order, time zones).
- Keep the original structure, aliases and comments so both versions diff line by line.
- If there is no direct equivalent, say so and give the closest option with its trade-off.
- Do not invent table definitions; mark any column type you rely on as an assumption.
Output format:
1. Translated query in one code block.
2. Change table with columns: # | Original | Translated | Category | Same behavior? | Edge case to test
3. Test checklist: 3-6 inputs or queries to run on both databases to confirm results match.
End with one line listing assumptions about data types, collation or server settings that could still change results.Example output
Tips and common edits
Why this works
- Forcing every change into a table stops the model from silently rewriting functions whose behavior differs, like CONCAT with NULLs.
- Asking whether results must match row for row decides tricky choices such as ILIKE versus LIKE and NULL sort order.
- The test checklist turns flagged differences into concrete checks you can run on both databases before shipping.
Use this in ChatGPT, Claude or Gemini when porting reports, migrations or app queries to another database. Paste the full query and know both database versions and whether exact result parity matters.
Common edits
- Paste the CREATE TABLE statements too so column types stop being assumptions.
- Ask for a stored procedure or view translation instead of a single query.
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
Keep exploring
More like this
Design a Normalized Database Schema from a Plain Feature Description
Turns a plain-language feature description into a normalized relational schema with typed columns, keys, constraints, ready-to-run CREATE TABLE SQL, example queries and trade-offs.
Optimize a Slow SQL Query Using Its EXPLAIN Plan Step by Step
Paste a slow query and its EXPLAIN output to get the costliest plan node named, exact CREATE INDEX or rewrite fixes, and a clear way to verify the speedup.
Find and Fix Data Quality Issues with Ready-to-Run SQL Checks
Paste your schema and get SQL queries that catch duplicates, NULLs, orphaned foreign keys and out-of-range values, each with what a bad result means and a fix.
Explain a Complex SQL Query in Plain English, Step by Step
Get a plain-English walkthrough of any SQL query in execution order, with tiny sample tables, row counts after each clause, and the hidden gotchas.
Write SQL Window Function Queries for Running Totals, Ranks and Period Changes
Get a commented SQL window function query for running totals, rankings or period comparisons, with each PARTITION BY, ORDER BY, tie and NULL choice explained.
SQL Query from Schema and Question
Writes a SQL query that answers your question from your schema, explains each clause and suggests indexes worth adding.