Getting started
Quickstart
Install SQLBabel, check a file and translate it into DuckDB SQL.
SQLBabel translates Snowflake and Databricks SQL into DuckDB SQL with rules proven against real warehouse results, and refuses anything unproven with a precise reason. This page installs it, checks a Snowflake file and converts it.
Install
Section titled “Install”SQLBabel installs from PyPI with Python 3.12 or newer. The package ships the sqlbabel command and
the Python library, with DuckDB’s library beside them.
pip install sqlbabelsqlbabel --versionBuild from source
Section titled “Build from source”To build the command line from the repository instead, use Rust. The repository pins its toolchain
in rust-toolchain.toml, which rustup installs on first use.
git clone https://github.com/sqlstack-io/sqlbabelcd sqlbabelcargo build --release -p sqlbabelThe binary links DuckDB’s prebuilt shared library, which the build downloads to
target/duckdb-download/<target triple>/<DuckDB version>. cargo run puts it on the library path
for you:
cargo run --release -p sqlbabel -- check query.sqlTo run target/release/sqlbabel directly, point the library path at that directory:
LD_LIBRARY_PATH=target/duckdb-download/x86_64-unknown-linux-gnu/v2.0.0 target/release/sqlbabel check query.sqlUse DYLD_LIBRARY_PATH on macOS and PATH on Windows.
Check a file
Section titled “Check a file”check needs no schema. It parses the SQL and reports what Snowflake would reject.
-- orders.sqlSELECT customer_id, SUM(total) AS revenueFROM ordersWHERE status = 'shipped'GROUP BY customer_idQUALIFY revenue > 100$ sqlbabel check orders.sqlerror[SBL0203]: QUALIFY needs a window function --> orders.sql:5:1 |5 | QUALIFY revenue > 100 | ^^^^^^^^^^^^^^^^^^^^^ QUALIFY is used without a window function in the SELECT list or QUALIFY | = help: move the condition to WHERE or HAVING, or filter on a window function's resultsqlbabel check: found 1 problemMove the condition to HAVING SUM(total) > 100 and check reports no problems.
Convert a file
Section titled “Convert a file”Conversion types every expression, so it needs the columns and Snowflake types of the relations a
statement reads. Declare them in a source file under sources/ in the folder you run sqlbabel
from (see Projects):
sources: - name: orders columns: - name: order_id type: NUMBER(38,0) - name: customer_id type: NUMBER(38,0) - name: status type: VARCHAR - name: total type: NUMBER(12,2) - name: ordered_at type: TIMESTAMP_NTZ$ sqlbabel convert revenue.sql --no-configSELECT "ORDERS"."CUSTOMER_ID" AS "CUSTOMER_ID", CAST(sum("ORDERS"."TOTAL") AS DECIMAL(24, 2)) AS "REVENUE"FROM "ORDERS"WHERE ("ORDERS"."STATUS" = 'shipped')GROUP BY "ORDERS"."CUSTOMER_ID"sqlbabel convert: done, convertedThe DuckDB SQL goes to standard output and the progress lines to standard error, so
sqlbabel convert revenue.sql … > revenue.duckdb.sql keeps only the SQL.
Some Snowflake behaviour has no exact match in DuckDB, such as HASH. For each of these known
differences you refuse it, allow it or replace it with your own SQL, in sqlbabel.toml in the
current directory or the file --config names. Without one, or with --no-config, convert
uses the defaults.
The defaults refuse five known differences,
variant_chain_type, source_variant_json, project_udf, hash and sequences,
and allow the rest with a warning.
Can return a different value
lists the ones whose values can differ from Snowflake’s with no error, and their
defaults.
See Refuse, allow or replace to change them.
Next steps
Section titled “Next steps”- Reading diagnostics: the output format and JSON fields.
sqlbabel census: see which files of a project convert, and why the rest don’t.- Playground: try SQL in the browser.