Guides
Refuse, allow or replace
When something can't convert exactly: refuse, allow or replace each known difference between Snowflake and DuckDB.
Some Snowflake behaviour has no exact match in DuckDB. HASH is one: DuckDB computes its own
hash, consistent within one run but never Snowflake’s value. SQLBabel knows each such case, called
a known difference, and says what differs, when relying on it is fine and when it gives a wrong
result. Known differences lists every one.
When a statement needs a known difference, you choose what happens:
| Choice | What happens | How |
|---|---|---|
| Refuse | The statement isn’t converted. SBL0008 points at the construct. |
name = false under [allow] in sqlbabel.toml. The default for five. |
| Allow | The statement converts. A warning names the known difference it relies on. | name = true under [allow]. The default for the rest. |
| Replace | Calls to a Snowflake function use your own DuckDB SQL. | One file under overrides/. |
--strict refuses every known difference, whatever [allow] says, and every replacement that
recorded cases haven’t verified. What the session and the schema state still counts: a session
that runs in UTC, and the TIMESTAMP_TZ offsets the schema declares.
Refuse
Section titled “Refuse”A refused known difference stops the statement at the construct that needs it:
$ sqlbabel convert due.sql --no-configerror[SBL0008]: HASH gives a different value in DuckDB --> due.sql:2:8 |2 | HASH(customer_id) AS bucket | ^^^^^^^^^^^^^^^^^ DuckDB computes its own hash, never Snowflake's | = note: Equal inputs still get equal hashes within one run. = note: fine when: Joins, grouping, removing duplicates and spotting changed rows by hash. = note: wrong when: Storing, comparing or sorting by the hash value itself: it differs, with no error. = help: allow it with hash = true under [allow] in a sqlbabel.toml in the project folder; `sqlbabel explain hash` says when it is safesqlbabel convert: refused, 1 refusalconvert, function, census and index read your choices from the
project’s sqlbabel.toml, or from the file --config names, on top of the
defaults. Without one, they use the defaults alone.
The defaults allow every known difference except these five, which they refuse:
hash,sequences,source_variant_jsonandvariant_chain_type, whose values can differ from Snowflake’s with no error.project_udf, untilpython_runtime = trueunder[project]says a Python runtime registers the project’s functions.
sqlbabel explain --differences lists how the defaults and your sqlbabel.toml treat each one.
--no-config uses the defaults alone even where a sqlbabel.toml exists.
Allowing a known difference is a decision about your data, so read its entry first: it says when
the converted SQL gives Snowflake’s result and when it doesn’t. List it under [allow] in
sqlbabel.toml, true to allow it and false to refuse it:
[allow]hash = trueA name that isn’t a known difference is an error that names the nearest one. Some known
differences can return a different value
with no error, and sqlbabel explain --differences marks
them value. To convert only what is exact or fails with an error, refuse each of those that the
defaults allow:
[allow]user_override = falsedeclared_offset = falsesession_timezone_utc = falserandom = falseuuid = falsecurrent_time = falseA conversion that relies on an allowed known difference names it in its last line on standard
error, and --verbose adds a warning at each use:
$ sqlbabel convert due.sqlSELECT "ORDERS"."ORDER_ID" AS "ORDER_ID", CAST( CAST(hash(CAST("ORDERS"."CUSTOMER_ID" AS HUGEINT)) AS HUGEINT) - 9223372036854775808 AS DECIMAL(19, 0) ) AS "BUCKET"FROM "ORDERS"sqlbabel convert: done, converted (1 known difference allowed: hash — sqlbabel explain hash)Replace
Section titled “Replace”Replace a Snowflake function with your own DuckDB SQL when you know what your data needs. Put a
FUNCTION() file with replaces and dialect duckdb in the project’s overrides/ folder, or name
one with --overrides:
FUNCTION ( arguments (x NUMBER(38,0)), returns NUMBER(38,0), replaces HASH, dialect duckdb);x % 16Every call then uses your SQL, created as a macro ahead of the converted statement. Whether it gives Snowflake’s result is your decision: a conversion relying on it names it on standard error.
[replace] in sqlbabel.toml names another folder for them, and lists the replacements you
have verified:
[replace]folder = "duckdb_overrides"verified = { HASH = "<sha256>" }--strict refuses a replacement until it is verified for its exact body: listed under
verified, or passed as --verified-override NAME=SHA256, with the SHA-256 that convert --json
reports under overrides. A changed body is unverified again.
| Flag | Effect |
|---|---|
--config <file> |
The configuration file. Default the project’s sqlbabel.toml, or the defaults alone without one. |
--no-config |
Use the defaults alone even where a sqlbabel.toml exists. |
--strict |
Refuse every known difference, whatever [allow] says, and every replacement that isn’t verified. |
--python-runtime |
Confirm a Python runtime registers the project’s Python functions. |
A project can confirm the Python runtime for every run with python_runtime = true under
[project] in its sqlbabel.toml; see Projects.