Skip to content

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.

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 sqlbabel
sqlbabel --version

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/sqlbabel
cd sqlbabel
cargo build --release -p sqlbabel

The 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.sql

To 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.sql

Use DYLD_LIBRARY_PATH on macOS and PATH on Windows.

check needs no schema. It parses the SQL and reports what Snowflake would reject.

-- orders.sql
SELECT customer_id, SUM(total) AS revenue
FROM orders
WHERE status = 'shipped'
GROUP BY customer_id
QUALIFY revenue > 100
$ sqlbabel check orders.sql
error[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 result
sqlbabel check: found 1 problem

Move the condition to HAVING SUM(total) > 100 and check reports no problems.

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/orders.yml
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-config
SELECT
"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, converted

The 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.