[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-71012":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":25,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":47,"readmeContent":48,"aiSummary":49,"trendingCount":16,"starSnapshotCount":16,"syncStatus":50,"lastSyncTime":51,"discoverSource":52},71012,"sqlglot","tobymao\u002Fsqlglot","tobymao","Python SQL Parser and Transpiler","https:\u002F\u002Fsqlglot.com\u002F",null,"Python",9318,1167,50,1,0,10,28,92,30,108.4,"MIT License",false,"main",true,[27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46],"bigquery","clickhouse","databricks","duckdb","hive","mysql","optimizer","parser","postgres","presto","python","redshift","snowflake","spark","sql","sqlite","sqlparser","transpiler","trino","tsql","2026-06-12 04:00:58","![SQLGlot logo](sqlglot.png)\n\nSQLGlot is a no-dependency SQL parser, transpiler, optimizer, and engine. It can be used to format SQL or translate between [31 different dialects](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fsqlglot\u002Fdialects\u002F__init__.py) like [DuckDB](https:\u002F\u002Fduckdb.org\u002F), [Presto](https:\u002F\u002Fprestodb.io\u002F) \u002F [Trino](https:\u002F\u002Ftrino.io\u002F), [Spark](https:\u002F\u002Fspark.apache.org\u002F) \u002F [Databricks](https:\u002F\u002Fwww.databricks.com\u002F), [Snowflake](https:\u002F\u002Fwww.snowflake.com\u002Fen\u002F), and [BigQuery](https:\u002F\u002Fcloud.google.com\u002Fbigquery\u002F). It aims to read a wide variety of SQL inputs and output syntactically and semantically correct SQL in the targeted dialects.\n\nIt is a very comprehensive generic SQL parser with a robust [test suite](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Ftests\u002F). It is also quite [performant](#benchmarks), while being written purely in Python.\n\nYou can easily [customize](#custom-dialects) the parser, [analyze](#metadata) queries, traverse expression trees, and programmatically [build](#build-and-modify-sql) SQL.\n\nSQLGlot can detect a variety of [syntax errors](#parser-errors), such as unbalanced parentheses, incorrect usage of reserved keywords, and so on. These errors are highlighted and dialect incompatibilities can warn or raise depending on configurations.\n\nLearn more about SQLGlot in the API [documentation](https:\u002F\u002Fsqlglot.com\u002F) and the expression tree [primer](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fposts\u002Fast_primer.md).\n\nContributions are very welcome in SQLGlot; read the [contribution guide](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002FCONTRIBUTING.md) and the [onboarding document](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fposts\u002Fonboarding.md) to get started!\n\n## Table of Contents\n\n* [Install](#install)\n* [Versioning](#versioning)\n* [Get in Touch](#get-in-touch)\n* [FAQ](#faq)\n* [Examples](#examples)\n   * [Formatting and Transpiling](#formatting-and-transpiling)\n   * [Metadata](#metadata)\n   * [Parser Errors](#parser-errors)\n   * [Unsupported Errors](#unsupported-errors)\n   * [Build and Modify SQL](#build-and-modify-sql)\n   * [SQL Optimizer](#sql-optimizer)\n   * [AST Introspection](#ast-introspection)\n   * [AST Diff](#ast-diff)\n   * [Custom Dialects](#custom-dialects)\n   * [SQL Execution](#sql-execution)\n* [Used By](#used-by)\n* [Documentation](#documentation)\n* [Run Tests and Lint](#run-tests-and-lint)\n* [Deployment](#deployment)\n* [Benchmarks](#benchmarks)\n* [Optional Dependencies](#optional-dependencies)\n* [Supported Dialects](#supported-dialects)\n\n## Install\n\nFrom PyPI:\n\n```bash\n# Pure python version\npip3 install sqlglot\n\n# C extensions compiled with mypyc\n# prebuilt wheel if available for your platform, otherwise builds from source\npip3 install \"sqlglot[c]\"\n```\n\nOr with a local checkout:\n\n```\n# Optionally prefix with UV=1 to use uv for the installation\nmake install\n```\n\nRequirements for development (optional):\n\n```\n# Optionally prefix with UV=1 to use uv for the installation\nmake install-dev\n```\n\n## Versioning\n\nGiven a version number `MAJOR`.`MINOR`.`PATCH`, SQLGlot uses the following versioning strategy:\n\n- The `PATCH` version is incremented when there are backwards-compatible fixes or feature additions.\n- The `MINOR` version is incremented when there are backwards-incompatible fixes or feature additions.\n- The `MAJOR` version is incremented when there are significant backwards-incompatible fixes or feature additions.\n\n## Get in Touch\n\nWe'd love to hear from you. Join our community [Slack channel](https:\u002F\u002Ftobikodata.com\u002Fslack)!\n\n## FAQ\n\nI tried to parse SQL that should be valid but it failed, why did that happen?\n\n* Most of the time, issues like this occur because the \"source\" dialect is omitted during parsing. For example, this is how to correctly parse a SQL query written in Spark SQL: `parse_one(sql, dialect=\"spark\")` (alternatively: `read=\"spark\"`). If no dialect is specified, `parse_one` will attempt to parse the query according to the \"SQLGlot dialect\", which is designed to be a superset of all supported dialects. If you tried specifying the dialect and it still doesn't work, please file an issue.\n\nI tried to output SQL but it's not in the correct dialect!\n\n* Like parsing, generating SQL also requires the target dialect to be specified, otherwise the SQLGlot dialect will be used by default. For example, to transpile a query from Spark SQL to DuckDB, do `parse_one(sql, dialect=\"spark\").sql(dialect=\"duckdb\")` (alternatively: `transpile(sql, read=\"spark\", write=\"duckdb\")`).\n\nWhat happened to sqlglot.dataframe?\n\n* The PySpark dataframe api was moved to a standalone library called [SQLFrame](https:\u002F\u002Fgithub.com\u002Feakmanrq\u002Fsqlframe) in v24. It now allows you to run queries as opposed to just generate SQL.\n\n## Examples\n\n### Formatting and Transpiling\n\nEasily translate from one dialect to another. For example, date\u002Ftime functions vary between dialects and can be hard to deal with:\n\n```python\nimport sqlglot\nsqlglot.transpile(\"SELECT EPOCH_MS(1618088028295)\", read=\"duckdb\", write=\"hive\")[0]\n```\n\n```sql\n'SELECT FROM_UNIXTIME(1618088028295 \u002F POW(10, 3))'\n```\n\nSQLGlot can even translate custom time formats:\n\n```python\nimport sqlglot\nsqlglot.transpile(\"SELECT STRFTIME(x, '%y-%-m-%S')\", read=\"duckdb\", write=\"hive\")[0]\n```\n\n```sql\n\"SELECT DATE_FORMAT(x, 'yy-M-ss')\"\n```\n\nIdentifier delimiters and data types can be translated as well:\n\n```python\nimport sqlglot\n\n# Spark SQL requires backticks (`) for delimited identifiers and uses `FLOAT` over `REAL`\nsql = \"\"\"WITH baz AS (SELECT a, c FROM foo WHERE a = 1) SELECT f.a, b.b, baz.c, CAST(\"b\".\"a\" AS REAL) d FROM foo f JOIN bar b ON f.a = b.a LEFT JOIN baz ON f.a = baz.a\"\"\"\n\n# Translates the query into Spark SQL, formats it, and delimits all of its identifiers\nprint(sqlglot.transpile(sql, write=\"spark\", identify=True, pretty=True)[0])\n```\n\n```sql\nWITH `baz` AS (\n  SELECT\n    `a`,\n    `c`\n  FROM `foo`\n  WHERE\n    `a` = 1\n)\nSELECT\n  `f`.`a`,\n  `b`.`b`,\n  `baz`.`c`,\n  CAST(`b`.`a` AS FLOAT) AS `d`\nFROM `foo` AS `f`\nJOIN `bar` AS `b`\n  ON `f`.`a` = `b`.`a`\nLEFT JOIN `baz`\n  ON `f`.`a` = `baz`.`a`\n```\n\nComments are also preserved on a best-effort basis:\n\n```python\nsql = \"\"\"\n\u002F* multi\n   line\n   comment\n*\u002F\nSELECT\n  tbl.cola \u002F* comment 1 *\u002F + tbl.colb \u002F* comment 2 *\u002F,\n  CAST(x AS SIGNED), # comment 3\n  y               -- comment 4\nFROM\n  bar \u002F* comment 5 *\u002F,\n  tbl #          comment 6\n\"\"\"\n\n# Note: MySQL-specific comments (`#`) are converted into standard syntax\nprint(sqlglot.transpile(sql, read='mysql', pretty=True)[0])\n```\n\n```sql\n\u002F* multi\n   line\n   comment\n*\u002F\nSELECT\n  tbl.cola \u002F* comment 1 *\u002F + tbl.colb \u002F* comment 2 *\u002F,\n  CAST(x AS INT), \u002F* comment 3 *\u002F\n  y \u002F* comment 4 *\u002F\nFROM bar \u002F* comment 5 *\u002F, tbl \u002F*          comment 6 *\u002F\n```\n\n\n### Metadata\n\nYou can explore SQL with expression helpers to do things like find columns and tables in a query:\n\n```python\nfrom sqlglot import parse_one, exp\n\n# print all column references (a and b)\nfor column in parse_one(\"SELECT a, b + 1 AS c FROM d\").find_all(exp.Column):\n    print(column.alias_or_name)\n\n# find all projections in select statements (a and c)\nfor select in parse_one(\"SELECT a, b + 1 AS c FROM d\").find_all(exp.Select):\n    for projection in select.expressions:\n        print(projection.alias_or_name)\n\n# find all tables (x, y, z)\nfor table in parse_one(\"SELECT * FROM x JOIN y JOIN z\").find_all(exp.Table):\n    print(table.name)\n```\n\nRead the [ast primer](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fposts\u002Fast_primer.md) to learn more about SQLGlot's internals.\n\n### Parser Errors\n\nWhen the parser detects an error in the syntax, it raises a `ParseError`:\n\n```python\nimport sqlglot\nsqlglot.transpile(\"SELECT foo FROM (SELECT baz FROM t\")\n```\n\n```\nsqlglot.errors.ParseError: Expecting ). Line 1, Col: 34.\n  SELECT foo FROM (SELECT baz FROM t\n                                   ~\n```\n\nStructured syntax errors are accessible for programmatic use:\n\n```python\nimport sqlglot.errors\ntry:\n    sqlglot.transpile(\"SELECT foo FROM (SELECT baz FROM t\")\nexcept sqlglot.errors.ParseError as e:\n    print(e.errors)\n```\n\n```python\n[{\n  'description': 'Expecting )',\n  'line': 1,\n  'col': 34,\n  'start_context': 'SELECT foo FROM (SELECT baz FROM ',\n  'highlight': 't',\n  'end_context': '',\n  'into_expression': None\n}]\n```\n\n### Unsupported Errors\n\nIt may not be possible to translate some queries between certain dialects. For these cases, SQLGlot may emit a warning and will proceed to do a best-effort translation by default:\n\n```python\nimport sqlglot\nsqlglot.transpile(\"SELECT APPROX_DISTINCT(a, 0.1) FROM foo\", read=\"presto\", write=\"hive\")\n```\n\n```sql\nAPPROX_COUNT_DISTINCT does not support accuracy\n'SELECT APPROX_COUNT_DISTINCT(a) FROM foo'\n```\n\nThis behavior can be changed by setting the [`unsupported_level`](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fb0e8dc96ba179edb1776647b5bde4e704238b44d\u002Fsqlglot\u002Ferrors.py#L9) attribute. For example, we can set it to either `RAISE` or `IMMEDIATE` to ensure an exception is raised instead:\n\n```python\nimport sqlglot\nsqlglot.transpile(\"SELECT APPROX_DISTINCT(a, 0.1) FROM foo\", read=\"presto\", write=\"hive\", unsupported_level=sqlglot.ErrorLevel.RAISE)\n```\n\n```\nsqlglot.errors.UnsupportedError: APPROX_COUNT_DISTINCT does not support accuracy\n```\n\nThere are queries that require additional information to be accurately transpiled, such as the schemas of the tables referenced in them. This is because certain transformations are type-sensitive, meaning that type inference is needed in order to understand their semantics. Even though the `qualify` and `annotate_types` optimizer [rules](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Ftree\u002Fmain\u002Fsqlglot\u002Foptimizer) can help with this, they are not used by default because they add significant overhead and complexity.\n\nTranspilation is generally a hard problem, so SQLGlot employs an \"incremental\" approach to solving it. This means that there may be dialect pairs that currently lack support for some inputs, but this is expected to improve over time. We highly appreciate well-documented and tested issues or PRs, so feel free to [reach out](#get-in-touch) if you need guidance!\n\n### Build and Modify SQL\n\nSQLGlot supports incrementally building SQL expressions:\n\n```python\nfrom sqlglot import select, condition\n\nwhere = condition(\"x=1\").and_(\"y=1\")\nselect(\"*\").from_(\"y\").where(where).sql()\n```\n\n```sql\n'SELECT * FROM y WHERE x = 1 AND y = 1'\n```\n\nIt's possible to modify a parsed tree:\n\n```python\nfrom sqlglot import parse_one\nparse_one(\"SELECT x FROM y\").from_(\"z\").sql()\n```\n\n```sql\n'SELECT x FROM z'\n```\n\nParsed expressions can also be transformed recursively by applying a mapping function to each node in the tree:\n\n```python\nfrom sqlglot import exp, parse_one\n\nexpression_tree = parse_one(\"SELECT a FROM x\")\n\ndef transformer(node):\n    if isinstance(node, exp.Column) and node.name == \"a\":\n        return parse_one(\"FUN(a)\")\n    return node\n\ntransformed_tree = expression_tree.transform(transformer)\ntransformed_tree.sql()\n```\n\n```sql\n'SELECT FUN(a) FROM x'\n```\n\n### SQL Optimizer\n\nSQLGlot can rewrite queries into an \"optimized\" form. It performs a variety of [techniques](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fsqlglot\u002Foptimizer\u002Foptimizer.py) to create a new canonical AST. This AST can be used to standardize queries or provide the foundations for implementing an actual engine. For example:\n\n```python\nimport sqlglot\nfrom sqlglot.optimizer import optimize\n\nprint(\n    optimize(\n        sqlglot.parse_one(\"\"\"\n            SELECT A OR (B OR (C AND D))\n            FROM x\n            WHERE Z = date '2021-01-01' + INTERVAL '1' month OR 1 = 0\n        \"\"\"),\n        schema={\"x\": {\"A\": \"INT\", \"B\": \"INT\", \"C\": \"INT\", \"D\": \"INT\", \"Z\": \"STRING\"}}\n    ).sql(pretty=True)\n)\n```\n\n```sql\nSELECT\n  (\n    \"x\".\"a\" \u003C> 0 OR \"x\".\"b\" \u003C> 0 OR \"x\".\"c\" \u003C> 0\n  )\n  AND (\n    \"x\".\"a\" \u003C> 0 OR \"x\".\"b\" \u003C> 0 OR \"x\".\"d\" \u003C> 0\n  ) AS \"_col_0\"\nFROM \"x\" AS \"x\"\nWHERE\n  CAST(\"x\".\"z\" AS DATE) = CAST('2021-02-01' AS DATE)\n```\n\n### AST Introspection\n\nYou can see the AST version of the parsed SQL by calling `repr`:\n\n```python\nfrom sqlglot import parse_one\nprint(repr(parse_one(\"SELECT a + 1 AS z\")))\n```\n\n```python\nSelect(\n  expressions=[\n    Alias(\n      this=Add(\n        this=Column(\n          this=Identifier(this=a, quoted=False)),\n        expression=Literal(this=1, is_string=False)),\n      alias=Identifier(this=z, quoted=False))])\n```\n\n### AST Diff\n\nSQLGlot can calculate the semantic difference between two expressions and output changes in a form of a sequence of actions needed to transform a source expression into a target one:\n\n```python\nfrom sqlglot import diff, parse_one\ndiff(parse_one(\"SELECT a + b, c, d\"), parse_one(\"SELECT c, a - b, d\"))\n```\n\n```python\n[\n  Remove(expression=Add(\n    this=Column(\n      this=Identifier(this=a, quoted=False)),\n    expression=Column(\n      this=Identifier(this=b, quoted=False)))),\n  Insert(expression=Sub(\n    this=Column(\n      this=Identifier(this=a, quoted=False)),\n    expression=Column(\n      this=Identifier(this=b, quoted=False)))),\n  Keep(\n    source=Column(this=Identifier(this=a, quoted=False)),\n    target=Column(this=Identifier(this=a, quoted=False))),\n  ...\n]\n```\n\nSee also: [Semantic Diff for SQL](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fposts\u002Fsql_diff.md).\n\n### Custom Dialects\n\n[Dialects](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Ftree\u002Fmain\u002Fsqlglot\u002Fdialects) can be added by subclassing `Dialect`:\n\n```python\nfrom sqlglot import exp\nfrom sqlglot.dialects.dialect import Dialect\nfrom sqlglot.generator import Generator\nfrom sqlglot.tokens import Tokenizer, TokenType\n\n\nclass Custom(Dialect):\n    class Tokenizer(Tokenizer):\n        QUOTES = [\"'\", '\"']\n        IDENTIFIERS = [\"`\"]\n\n        KEYWORDS = {\n            **Tokenizer.KEYWORDS,\n            \"INT64\": TokenType.BIGINT,\n            \"FLOAT64\": TokenType.DOUBLE,\n        }\n\n    class Generator(Generator):\n        TRANSFORMS = {exp.Array: lambda self, e: f\"[{self.expressions(e)}]\"}\n\n        TYPE_MAPPING = {\n            exp.DataType.Type.TINYINT: \"INT64\",\n            exp.DataType.Type.SMALLINT: \"INT64\",\n            exp.DataType.Type.INT: \"INT64\",\n            exp.DataType.Type.BIGINT: \"INT64\",\n            exp.DataType.Type.DECIMAL: \"NUMERIC\",\n            exp.DataType.Type.FLOAT: \"FLOAT64\",\n            exp.DataType.Type.DOUBLE: \"FLOAT64\",\n            exp.DataType.Type.BOOLEAN: \"BOOL\",\n            exp.DataType.Type.TEXT: \"STRING\",\n        }\n\nprint(Dialect[\"custom\"])\n```\n\n```\n\u003Cclass '__main__.Custom'>\n```\n\n### SQL Execution\n\nSQLGlot is able to interpret SQL queries, where the tables are represented as Python dictionaries. The engine is not supposed to be fast, but it can be useful for unit testing and running SQL natively across Python objects. Additionally, the foundation can be easily integrated with fast compute kernels, such as [Arrow](https:\u002F\u002Farrow.apache.org\u002Fdocs\u002Findex.html) and [Pandas](https:\u002F\u002Fpandas.pydata.org\u002F).\n\nThe example below showcases the execution of a query that involves aggregations and joins:\n\n```python\nfrom sqlglot.executor import execute\n\ntables = {\n    \"sushi\": [\n        {\"id\": 1, \"price\": 1.0},\n        {\"id\": 2, \"price\": 2.0},\n        {\"id\": 3, \"price\": 3.0},\n    ],\n    \"order_items\": [\n        {\"sushi_id\": 1, \"order_id\": 1},\n        {\"sushi_id\": 1, \"order_id\": 1},\n        {\"sushi_id\": 2, \"order_id\": 1},\n        {\"sushi_id\": 3, \"order_id\": 2},\n    ],\n    \"orders\": [\n        {\"id\": 1, \"user_id\": 1},\n        {\"id\": 2, \"user_id\": 2},\n    ],\n}\n\nexecute(\n    \"\"\"\n    SELECT\n      o.user_id,\n      SUM(s.price) AS price\n    FROM orders o\n    JOIN order_items i\n      ON o.id = i.order_id\n    JOIN sushi s\n      ON i.sushi_id = s.id\n    GROUP BY o.user_id\n    \"\"\",\n    tables=tables\n)\n```\n\n```python\nuser_id price\n      1   4.0\n      2   3.0\n```\n\nSee also: [Writing a Python SQL engine from scratch](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fposts\u002Fpython_sql_engine.md).\n\n## Used By\n\n* [SQLMesh](https:\u002F\u002Fgithub.com\u002FTobikoData\u002Fsqlmesh)\n* [Apache Superset](https:\u002F\u002Fgithub.com\u002Fapache\u002Fsuperset)\n* [Dagster](https:\u002F\u002Fgithub.com\u002Fdagster-io\u002Fdagster)\n* [Fugue](https:\u002F\u002Fgithub.com\u002Ffugue-project\u002Ffugue)\n* [Ibis](https:\u002F\u002Fgithub.com\u002Fibis-project\u002Fibis)\n* [dlt](https:\u002F\u002Fgithub.com\u002Fdlt-hub\u002Fdlt)\n* [mysql-mimic](https:\u002F\u002Fgithub.com\u002Fkelsin\u002Fmysql-mimic)\n* [Querybook](https:\u002F\u002Fgithub.com\u002Fpinterest\u002Fquerybook)\n* [Quokka](https:\u002F\u002Fgithub.com\u002Fmarsupialtail\u002Fquokka)\n* [Splink](https:\u002F\u002Fgithub.com\u002Fmoj-analytical-services\u002Fsplink)\n* [SQLFrame](https:\u002F\u002Fgithub.com\u002Feakmanrq\u002Fsqlframe)\n\n## Documentation\n\nSQLGlot uses [pdoc](https:\u002F\u002Fpdoc.dev\u002F) to serve its API documentation.\n\nA hosted version is on the [SQLGlot website](https:\u002F\u002Fsqlglot.com\u002F), or you can build locally with:\n\n```\nmake docs-serve\n```\n\n## Run Tests and Lint\n\n```\nmake style   # Only linter checks\nmake unit    # Only unit tests (pure Python)\nmake test    # Unit and integration tests (pure Python)\nmake unitc   # Only unit tests (mypyc compiled)\nmake testc   # Unit and integration tests (mypyc compiled)\nmake check   # Full test suite & linter checks\nmake clean   # Remove compiled C artifacts (.so files, build dirs)\n```\n\n## Deployment\n\nTo deploy a new SQLGlot version, follow these steps:\n\n1. Run `git pull` to make sure the local git repo is at the head of the main branch\n2. Do a `git tag` operation to bump the SQLGlot version, e.g. `git tag v28.5.0`\n3. Run `git push && git push --tags` to deploy the new version\n\n## Benchmarks\n\n[Benchmarks](https:\u002F\u002Fgithub.com\u002Ftobymao\u002Fsqlglot\u002Fblob\u002Fmain\u002Fbenchmarks\u002Fparse.py) run on Python 3.14.3 in seconds.\n\nsqlglot, sqltree, sqlparse, and sqlfluff are python based whereas sqloxide and polyglot-sql are rust bindings.\n\n|             Query |         sqlglot |      sqlglot[c] |         sqltree |         sqlparse |          sqlfluff |        sqloxide |    polyglot-sql |\n| ----------------- | --------------- | --------------- | --------------- | ---------------- | ----------------- | --------------- | --------------- |\n|              tpch | 0.002709 (1.00) | 0.000740 (0.27) | 0.002172 (0.80) |  0.014152 (5.22) |  0.241027 (88.97) | 0.000655 (0.24) | 0.000698 (0.26) |\n|             short | 0.000226 (1.00) | 0.000075 (0.33) | 0.000184 (0.81) |  0.000938 (4.15) | 0.031542 (139.47) | 0.000041 (0.18) | 0.000174 (0.77) |\n|   deep_arithmetic | 0.007760 (1.00) | 0.002015 (0.26) | 0.005927 (0.76) |              N\u002FA | 1.359824 (175.22) | 0.003117 (0.40) | 0.002964 (0.38) |\n|          large_in | 0.407987 (1.00) | 0.101644 (0.25) | 0.467943 (1.15) |              N\u002FA |               N\u002FA | 0.147765 (0.36) | 0.105854 (0.26) |\n|            values | 0.466734 (1.00) | 0.113762 (0.24) | 0.522797 (1.12) |              N\u002FA |               N\u002FA | 0.117628 (0.25) | 0.117169 (0.25) |\n|        many_joins | 0.011943 (1.00) | 0.002701 (0.23) | 0.009887 (0.83) |  0.059303 (4.97) | 1.246253 (104.35) | 0.002918 (0.24) | 0.002964 (0.25) |\n|       many_unions | 0.041321 (1.00) | 0.008291 (0.20) | 0.038249 (0.93) |              N\u002FA |  1.826401 (44.20) | 0.012395 (0.30) | 0.013087 (0.32) |\n| nested_subqueries | 0.001200 (1.00) | 0.000235 (0.20) |             N\u002FA |  0.003860 (3.22) |  0.089490 (74.56) | 0.000215 (0.18) | 0.000262 (0.22) |\n|      many_columns | 0.011821 (1.00) | 0.002825 (0.24) | 0.012722 (1.08) | 0.238510 (20.18) |  1.050386 (88.86) | 0.002515 (0.21) | 0.003765 (0.32) |\n|        large_case | 0.035822 (1.00) | 0.008593 (0.24) | 0.033578 (0.94) |              N\u002FA | 4.200220 (117.25) | 0.009870 (0.28) | 0.009442 (0.26) |\n|     complex_where | 0.032710 (1.00) | 0.006602 (0.20) |             N\u002FA |  0.136203 (4.16) |  2.492927 (76.21) | 0.006002 (0.18) | 0.007787 (0.24) |\n|         many_ctes | 0.017610 (1.00) | 0.003630 (0.21) | 0.012377 (0.70) |  0.123620 (7.02) |  0.657611 (37.34) | 0.004197 (0.24) | 0.003273 (0.19) |\n|      many_windows | 0.020790 (1.00) | 0.005751 (0.28) |             N\u002FA |  0.203144 (9.77) |  1.421216 (68.36) | 0.003941 (0.19) | 0.004570 (0.22) |\n|  nested_functions | 0.000703 (1.00) | 0.000189 (0.27) | 0.000754 (1.07) |  0.005082 (7.23) | 0.091007 (129.51) | 0.000168 (0.24) | 0.000225 (0.32) |\n|     large_strings | 0.005073 (1.00) | 0.001480 (0.29) | 0.014533 (2.86) |  0.049392 (9.74) |  0.320672 (63.22) | 0.001616 (0.32) | 0.002151 (0.42) |\n|      many_numbers | 0.103898 (1.00) | 0.024483 (0.24) | 0.120119 (1.16) |              N\u002FA |               N\u002FA | 0.031667 (0.30) | 0.026880 (0.26) |\n\n```\nmake bench            # Run parsing benchmark\nmake bench-optimize   # Run optimization benchmark\n```\n\n## Optional Dependencies\n\nSQLGlot uses [dateutil](https:\u002F\u002Fgithub.com\u002Fdateutil\u002Fdateutil) to simplify literal timedelta expressions. The optimizer will not simplify expressions like the following if the module cannot be found:\n\n```sql\nx + interval '1' month\n```\n\n## Supported Dialects\n\n| Dialect | Support Level |\n|---------|---------------|\n| Athena | Official |\n| BigQuery | Official |\n| ClickHouse | Official |\n| Databricks | Official |\n| Doris | Community |\n| Dremio | Community |\n| Drill | Community |\n| Druid | Community |\n| DuckDB | Official |\n| Exasol | Community |\n| Fabric | Community |\n| Hive | Official |\n| Materialize | Community |\n| MySQL | Official |\n| Oracle | Official |\n| Postgres | Official |\n| Presto | Official |\n| PRQL | Community |\n| Redshift | Official |\n| RisingWave | Community |\n| SingleStore | Community |\n| Snowflake | Official |\n| Solr | Community |\n| Spark | Official |\n| SQLite | Official |\n| StarRocks | Official |\n| Tableau | Official |\n| Teradata | Community |\n| Trino | Official |\n| TSQL | Official |\n| YDB | [Plugin](https:\u002F\u002Fpypi.org\u002Fproject\u002Fydb-sqlglot-plugin) |\n| MaxCompute | [Plugin](https:\u002F\u002Fpypi.org\u002Fproject\u002Fsqlglot-maxcompute) |\n\n**Official Dialects** are maintained by the core SQLGlot team with higher priority for bug fixes and feature additions.\n\n**Community Dialects** are developed and maintained primarily through community contributions. These are fully functional but may receive lower priority for issue resolution compared to officially supported dialects. We welcome and encourage community contributions to improve these dialects.\n\n**Plugin Dialects** (supported since v28.6.0) are third-party dialects developed and maintained in external repositories by independent contributors. These dialects are not part of the SQLGlot codebase and are distributed as separate packages. The SQLGlot team does not provide support or maintenance for plugin dialects — please direct any issues or feature requests to their respective repositories. See [Creating a Dialect Plugin](#creating-a-dialect-plugin) below for information on how to build your own.\n\n### Creating a Dialect Plugin\n\nIf your database isn't supported, you can create a plugin that registers a custom dialect via entry points. Create a package with your dialect class and register it in `setup.py`:\n\n```python\nfrom setuptools import setup\n\nsetup(\n    name=\"mydb-sqlglot-dialect\",\n    entry_points={\n        \"sqlglot.dialects\": [\n            \"mydb = my_package.dialect:MyDB\",\n        ],\n    },\n)\n```\n\nThe dialect will be automatically discovered and can be used like any built-in dialect:\n\n```python\nfrom sqlglot import transpile\ntranspile(\"SELECT * FROM t\", read=\"mydb\", write=\"postgres\")\n```\n\nSee the [Custom Dialects](#custom-dialects) section for implementation details.\n","SQLGlot 是一个无依赖的 SQL 解析器、转译器、优化器和引擎。它能够解析多种 SQL 方言，并支持在 31 种不同方言之间进行格式化或转换，如 DuckDB、Presto\u002FTrino、Spark\u002FDatabricks、Snowflake 和 BigQuery 等。项目具备强大的测试套件以确保其健壮性，并且完全用 Python 编写的同时保持了良好的性能。用户可以轻松地自定义解析器、分析查询、遍历表达式树以及通过编程方式构建 SQL。此外，SQLGlot 能够检测到诸如括号不匹配、保留关键字使用不当等多种语法错误，并根据配置发出警告或抛出异常。此工具非常适合需要处理跨数据库平台 SQL 语句兼容性的场景，或是对现有 SQL 进行优化和重构的情况。",2,"2026-06-11 03:35:27","high_star"]