Skip to content

Commit

Permalink
Add sqlglot
Browse files Browse the repository at this point in the history
  • Loading branch information
baniasbaabe committed Mar 10, 2024
1 parent 7ced6d6 commit eda2025
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions book/cooltools/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,46 @@
"output_path = 'fr.wav'\n",
"model.tts_to_file(text, speaker_ids['FR'], output_path, speed=speed)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Powerful SQL Parser and Transpiler with `SQLGlot`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With `SQLGlot`, you can parse, optimize, transpile and format SQL queries. \n",
"\n",
"You can even translate between 21 different flavours like DuckDB, Snowflake, Spark and Hive."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install sqlglot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sqlglot\n",
"\n",
"sqlglot.transpile(\"SELECT TOP 1 salary FROM employees WHERE age > 30\", read=\"tsql\", write=\"hive\")[0]\n",
"# SELECT salary FROM employees WHERE age > 30 LIMIT 1\n",
"\n",
"sqlglot.transpile(\"SELECT foo FROM (SELECT baz FROM t\")\n",
"#ParseError: Expecting ). Line 1, Col: 34. SELECT foo FROM (SELECT baz FROM t"
]
}
],
"metadata": {
Expand Down

0 comments on commit eda2025

Please sign in to comment.