---
title: "SQLGlot"
description: "SQLGlot is a Python SQL parser, transpiler, and optimizer that can parse and translate SQL between more than 30 dialects, including DuckDB, Snowflake, BigQuery, and Spark."
canonical: "https://motherduck.com/glossary/sqlglot/"
related:
  - title: "DuckLake Architecture Deep Dive"
    url: "https://motherduck.com/blog/ducklake-architecture-deep-dive/"
  - title: "DuckDB SQL | MotherDuck Docs"
    url: "https://motherduck.com/docs/sql-reference/duckdb-sql-reference/"
  - title: "Friendly SQL with DuckDB | MotherDuck"
    url: "https://motherduck.com/videos/friendly-sql-with-duckdb/"
---

# SQLGlot

> SQLGlot is a Python SQL parser, transpiler, and optimizer that can parse and translate SQL between more than 30 dialects, including DuckDB, Snowflake, BigQuery, and Spark.

## Overview

SQLGlot is a pure-Python library for parsing SQL into an abstract syntax tree (AST), analyzing or rewriting that tree, and generating SQL back out in a specified dialect. Its most common use is transpilation: converting a query written for one database's SQL dialect into the equivalent syntax for another, which is useful when migrating between databases, building cross-dialect tooling, or writing dialect-agnostic query generators. Beyond transpilation, SQLGlot also includes a query optimizer and a lightweight, in-memory SQL execution engine.

<glossary-callout guide="duckdb-book-brief" />

## Basic usage

```python
import sqlglot

sql = "SELECT EPOCH_MS(1700000000000) AS ts"
transpiled = sqlglot.transpile(sql, read="duckdb", write="hive")[0]
# 'SELECT FROM_UNIXTIME(1700000000000 / POW(10, 3)) AS ts'
```

You can also parse without converting dialects, walk the resulting expression tree, and programmatically build SQL from Python objects rather than string concatenation.

## SQLGlot and DuckDB

SQLGlot has first-class support for the DuckDB SQL dialect, including many of DuckDB's distinctive extensions such as `QUALIFY`, list and struct literals, and DuckDB-specific function names, which means it can transpile queries written in other dialects into idiomatic DuckDB SQL, and vice versa. This makes it a common building block for tools that need to run the same logical query across multiple engines — for example, a BI tool or semantic layer that wants to support both a cloud warehouse and a local DuckDB instance without maintaining separate handwritten SQL for each. SQLGlot's DuckDB dialect support does not require an actual DuckDB installation; it operates purely on SQL text and is a separate, independently maintained open-source project rather than being part of DuckDB itself.
