{"id":4776,"library":"sqlglotc","title":"SQLGlot C Extensions","description":"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.","status":"active","version":"30.4.2","language":"en","source_language":"en","source_url":"https://github.com/tobymao/sqlglot","tags":["python","sql","parser","transpiler","optimizer","performance","c-extensions","mypyc"],"install":[{"cmd":"pip install sqlglotc","lang":"bash","label":"Install sqlglotc directly"},{"cmd":"pip install \"sqlglot[c]\"","lang":"bash","label":"Install sqlglot with C extensions"}],"dependencies":[{"reason":"sqlglotc provides compiled extensions for sqlglot, making sqlglot a core dependency for its functionality.","package":"sqlglot","optional":false}],"imports":[{"note":"sqlglotc enhances sqlglot's performance transparently; users typically interact with sqlglot's API directly.","symbol":"transpile","correct":"from sqlglot import transpile"},{"note":"sqlglotc enhances sqlglot's performance transparently; users typically interact with sqlglot's API directly.","symbol":"parse_one","correct":"from sqlglot import parse_one"}],"quickstart":{"code":"import sqlglot\n\n# Example: Transpile SQL from DuckDB to Hive dialect\nduckdb_sql = \"SELECT EPOCH_MS(1618088028295)\"\nhive_sql = sqlglot.transpile(duckdb_sql, read='duckdb', write='hive')[0]\n\nprint(f\"Original DuckDB SQL: {duckdb_sql}\")\nprint(f\"Transpiled Hive SQL: {hive_sql}\")\n\n# Example: Parse a SQL query into an expression tree\nexpression = sqlglot.parse_one(\"SELECT id, name FROM users WHERE age > 18\")\nprint(f\"Parsed Expression: {expression}\")","lang":"python","description":"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."},"warnings":[{"fix":"Always pin `sqlglot` (and `sqlglotc`) to specific versions in production. Test upgrades thoroughly before deploying. Consult the `sqlglot` release notes for details on changes between versions.","message":"Minor version updates of `sqlglot` (and thus `sqlglotc`) can introduce backwards-incompatible changes in SQL parsing or transpilation logic, especially concerning specific dialect behaviors.","severity":"breaking","affected_versions":"All versions, particularly across minor increments (e.g., X.Y.Z to X.Y+1.Z)"},{"fix":"Always provide the `read` and `write` (or `dialect` for `parse_one`) arguments to ensure correct interpretation and generation of SQL for your specific dialect.","message":"Failing to explicitly specify the source (`read`) and target (`write`) SQL dialects when using `sqlglot.transpile` or `sqlglot.parse_one` can lead to incorrect parsing or output. `sqlglot` defaults to its 'SQLGlot dialect' if not specified.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you have a C compiler and the `mypyc` package installed (e.g., `pip install mypyc`) if encountering build errors during `sqlglotc` installation.","message":"If pre-built wheels for `sqlglotc` are not available for your specific platform or Python version, installation will attempt to build from source. This requires `mypyc` and a compatible C compiler (e.g., GCC or Clang) to be present on your system.","severity":"gotcha","affected_versions":"All versions without pre-built wheels"},{"fix":"Use `sqlglot` for transformation and analysis, but do not rely on it as a comprehensive SQL validator for all possible error conditions. Supplement with actual database execution or dedicated linting/validation tools.","message":"`sqlglot` primarily acts as a parser, transpiler, and optimizer, not a full SQL validator. While it detects many syntax errors, it may not catch all semantic or dialect-specific validation issues.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}