CrackSQL
📄 Unlock seamless SQL translation – effortless, precise, and efficient across databases~ 🐬
Demo •
Quick Start •
Feature Extension •
FAQ •
Community •
Contributors •
License
English | 简体中文
Star ⭐ and subscribe 🔔 for the latest features and improvements!
✨ Project Introduction
CrackSQL is a powerful SQL dialect translation tool that integrates rule-based strategies with LLMs for high accuracy.
It enables seamless conversion between dialects (e.g., PostgreSQL → MySQL) with flexible access through Python API, command line, and web interface.
- 03/2026: Our demo paper "CrackSQL: A Hybrid SQL Dialect Translation System Powered by Large Language Models" has been accepted by SIGMOD 2026! 🎉 🎉 🎉
- 09/2025: Our newly-developed benchmark PARROT (i.e., the first SQL-to-SQL benchmark) has been accepted by NeurIPS 2025 ! Welcome your submission to challenge our leaderboard! ⚔️ 🏆 🥇
- 06/2025: We have been invited by the Ploutos community to present CrackSQL at their livestream event! 🎥
- 04/2025: We have released our demo paper about this project that can be found online! 📚
- 03/2025: We have refactored the code and released our project across multiple open-source platforms (PyPI). We are currently working on new features and more contributors are welcomed! 👋 👫
- 02/2025: Our paper "Cracking SQL Barrier: An LLM-based Dialect Translation System" has been accepted by SIGMOD 2025! 🎉 🎉 🎉
📚 Features
- 🚀 Extensive Dialect Compatibility: Effortlessly translates between PostgreSQL, MySQL, and Oracle with tailored flexible strategies.
- 🎯 Precision & Advanced Processing: Achieves flawless translations with function-oriented query handling and cutting-edge model-based syntax matching through an adaptive local-to-global iteration strategy.
- 🔄 Versatile Access & Integration: Seamlessly integrates with Python API, command line, and web interface to meet all user requirements.
Currently, CrackSQL has integrated three modes for dialect translation, adopting the rules from SQLGlot and supporting a wide range of large language models (LLMs),
including prevalent models like GPT as well as the recent DeepSeek.
| Mode |
SQL Dialect |
LLM (w/o & w fine-tuned) |
Embedding Model (w/o & w fine-tuned) |
Cloud Service (e.g., 💬 GPT series) |
Local Deployed (e.g., 🤗 Hugging Face) |
Cloud Service (e.g., 💬 GPT series) |
Local Deployed (e.g., 🤗 Hugging Face) |
| Rule-only |
24 |
- |
- |
- |
- |
| LLM-direct |
✅ |
✅ |
✅ |
- |
- |
| Rule+LLM |
3 (pg/mysql/oracle) |
✅ |
✅ |
✅ |
✅ |
Additionally, the prerequisites for each mode are listed below, where SQL Parser (ANTLR) and Dialect Specification have already been provided.
Please refer to Feature Extension section to customize and enhance CrackSQL to make it more powerful for your own cases.
| Mode |
SQL Dialect |
Model Service |
| SQL Parser |
Dialect Specification |
Database Connection |
LLM |
Embedding Model |
| Rule-only |
✅ (SQLGlot) |
- |
- |
- |
- |
| LLM-direct |
- |
- |
- |
✅ |
- |
| Rule+LLM |
✅ (ANTLR) |
✅ |
✅ / - |
✅ |
✅ / - |
📊 Performance
The following table demonstrates the translation accuracy (%) of different methods over our collected benchmark (N/A denotes the dialect translation is not supported in Ora2Pg).
- (1) $Acc_{EX}$ indicates the translated SQL is syntactically correct and executable over the target database.
- (2) $Acc_{RES}$ represents the translated SQL delivers exactly the same result (including the displayed order) as the original ones.
Note that the required translation duration is highly dependent on the SQL complexity (e.g., the number of SQL syntax piece to be translated) and can vary from several seconds to minutes.
| Method |
PG → MySQL |
PG → MySQL |
MySQL → PG |
MySQL → PG |
PG → Oracle |
PG → Oracle |
|
$Acc_{EX}$ |
$Acc_{RES}$ |
$Acc_{EX}$ |
$Acc_{RES}$ |
$Acc_{EX}$ |
$Acc_{RES}$ |
| SQLGlot |
74.19 |
70.97 |
60.32 |
60.32 |
55.81 |
53.49 |
| jOOQ |
70.97 |
70.97 |
39.68 |
39.68 |
62.79 |
60.47 |
| Ora2Pg |
N/A |
N/A |
33.33 |
33.33 |
N/A |
N/A |
| SQLines |
9.68 |
9.68 |
31.75 |
31.75 |
53.49 |
48.84 |
| GPT-4o |
61.29 |
61.29 |
50.79 |
44.44 |
60.47 |
55.81 |
| CrackSQL (Ours) |
87.1 |
74.19 |
85.71 |
79.37 |
69.77 |
67.44 |
🎬 Demo
The following showcases the primary pages of the CrackSQL interface service, including the service guidance homepage and detailed translation process.
- Homepage of the deployed translation service:

- Detailed translation process of specific translation pair:

🕹 Quick Start
We have currently offered two methods (i.e., PyPI package and source code installation) to deploy CrackSQL.
Method 1: PyPI Package Installation
- Install the PyPI package at the official website.

# create virtual environment
conda create -n CrackSQL python=3.10
conda activate CrackSQL
# install PyPI package
pip install cracksql
- Run with the PyPI package. A running code example using this package is presented below:
from cracksql.cracksql import translate, initkb
def initkb_func():
try:
initkb("./init_config.yaml") # fill the basic configurations in the `.yaml` first
print("Knowledge base initialized successfully")
except Exception as e:
print(f"Knowledge base initialization failed: {str(e)}")
import traceback
traceback.print_exc()
def trans_func():
target_db_config = {
"host": "target database host",
"port": target database number (int type),
"user": "target database username",
"password": "target database password",
"db_name": "target database database name"
}
vector_config = {
"src_kb_name": "source database knowledge base name",
"tgt_kb_name": "target database knowledge base name"
}
try:
print("Starting SQL translation...")
translated_sql, model_ans_list, used_pieces, lift_histories = translate(
model_name="DeepSeek-R1-Distill-Qwen-32B",
src_sql='SELECT DISTINCT "t1"."id" , EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM CAST( "t1"."birthday" AS TIMESTAMP )) FROM "patient" AS "t1" INNER JOIN "examination" AS "t2" ON "t1"."id" = "t2"."id" WHERE "t2"."rvvt" = "+"',
src_dialect="postgresql",
tgt_dialect="mysql",
target_db_config=target_db_config,
vector_config=vector_config,
out_dir="./",
retrieval_on=False,
top_k=3
)
print("Translation completed!")
print(f"Translated SQL: {translated_sql}")
print(f"Model answer list: {model_ans_list}")
print(f"Used knowledge pieces: {used_pieces}")
print(f"Lift histories: {lift_histories}")
except Exception as e:
print(f"Error occurred during translation: {str(e)}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
initkb_func()
trans_func()
Method 2: Source Code Installation
1. Clone Repository
git clone https://github.com/weAIDB/CrackSQL.git
2. Use Frontend and Backend Application