SQLGlot C Extensions

30.4.2 · active · verified Sun Apr 12

sqlglotc provides performance-enhancing extensions for the sqlglot library, compiled using mypyc. SQLGlot is a robust, no-dependency Python library for parsing, transpiling, optimizing, and executing SQL across numerous dialects like DuckDB, Presto, Spark, Snowflake, and BigQuery. It aims to accurately process diverse SQL inputs and generate syntactically and semantically correct SQL in target dialects. The library is actively maintained with a rapid release cadence, currently at version 30.4.2.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the core `sqlglot` functionalities, `transpile` and `parse_one`, which are transparently accelerated by `sqlglotc` if installed. It shows converting a simple SQL query between dialects and parsing a query into an abstract syntax tree.

import sqlglot

# Example: Transpile SQL from DuckDB to Hive dialect
duckdb_sql = "SELECT EPOCH_MS(1618088028295)"
hive_sql = sqlglot.transpile(duckdb_sql, read='duckdb', write='hive')[0]

print(f"Original DuckDB SQL: {duckdb_sql}")
print(f"Transpiled Hive SQL: {hive_sql}")

# Example: Parse a SQL query into an expression tree
expression = sqlglot.parse_one("SELECT id, name FROM users WHERE age > 18")
print(f"Parsed Expression: {expression}")

view raw JSON →