whatisgithub

What is sqlglot?

tobymao/sqlglot — explained in plain English

Analysis updated 2026-06-24

9,236PythonAudience · dataComplexity · 2/5Setup · easy

In one sentence

A Python library that translates SQL queries between 31 database dialects like Snowflake, BigQuery, and DuckDB, and can also parse, analyze, reformat, and validate SQL with no external dependencies.

Mindmap

mindmap
  root((SQLGlot))
    What it does
      SQL dialect translation
      Query parsing
      Syntax validation
    Dialects
      Snowflake
      BigQuery
      DuckDB
      MySQL and more
    Features
      Table and column extraction
      Pretty printing
      Query optimizer
      Execution engine
    Setup
      pip install
      No dependencies
      Optional C extension
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Translate a Snowflake SQL query so it runs on BigQuery without rewriting it by hand

USE CASE 2

Parse a SQL query to extract all table names and column references for building a data lineage tool

USE CASE 3

Reformat messy one-liner SQL into consistently indented, readable style using the pretty-print mode

USE CASE 4

Catch syntax errors like missing parentheses before running a query against a production database

What is it built with?

PythonpipC extensions

How does it compare?

tobymao/sqlglotkhuedoan/homelabcomposiohq/awesome-codex-skills
Stars9,2369,2329,230
LanguagePythonPythonPython
Setup difficultyeasyhardeasy
Complexity2/55/52/5
Audiencedataops devopsdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min
No license terms are mentioned in the explanation.

So what is it?

SQLGlot is a Python library that reads SQL written for one database system and converts it to work with another. Think of it like a translation service for database query language: if you wrote a query that works in Snowflake but need it to run in BigQuery or DuckDB instead, SQLGlot handles that conversion automatically. The library supports 31 different SQL dialects, covering major platforms like MySQL, PostgreSQL, DuckDB, Spark, Databricks, Snowflake, BigQuery, Hive, Presto, Trino, and more. It has no external dependencies, which means you can add it to a Python project without pulling in other packages. An optional version with compiled C extensions is also available for faster performance. Beyond translation, SQLGlot can analyze SQL queries. You can use it to find all the tables a query references, list every column used, or inspect the internal structure of a query as a tree of nodes. This is useful when building tools that need to understand what a query is doing rather than simply running it. The library can also reformat SQL into a consistent, readable style with proper indentation. SQLGlot catches certain syntax mistakes as well, pointing out things like missing closing parentheses or keywords used in the wrong context. Errors include the specific line and column where the problem appears, which makes debugging easier. The library includes a built-in query optimizer and an experimental SQL execution engine. The execution engine is mainly for testing rather than production database workloads. SQLGlot is used by data infrastructure companies and developers who need to move queries between systems, build query analysis tools, or create products that work across multiple database platforms without rewriting SQL by hand.

Copy-paste prompts

Prompt 1
Using tobymao/sqlglot, show me the Python code to translate a Snowflake SQL query that uses QUALIFY and SEMI_STRUCTURED types into equivalent BigQuery SQL.
Prompt 2
With sqlglot, write a Python function that parses a SQL string and returns a list of all table names referenced in the query, including those inside subqueries.
Prompt 3
Using sqlglot's pretty-printing feature, take this messy one-liner SQL and reformat it with proper indentation and line breaks: SELECT a,b,c FROM t WHERE x=1 AND y=2 ORDER BY a
Prompt 4
How do I use sqlglot to validate a batch of SQL files and collect all syntax errors with their line and column numbers into a report?
Prompt 5
Show me how to install sqlglot with the optional C extension for faster parsing and confirm it is working with a quick dialect-conversion test.

Frequently asked questions

What is sqlglot?

A Python library that translates SQL queries between 31 database dialects like Snowflake, BigQuery, and DuckDB, and can also parse, analyze, reformat, and validate SQL with no external dependencies.

What language is sqlglot written in?

Mainly Python. The stack also includes Python, pip, C extensions.

What license does sqlglot use?

No license terms are mentioned in the explanation.

How hard is sqlglot to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is sqlglot for?

Mainly data.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.