-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed as not planned
Description
Hello :) and another issue:
BigQuery's NUMERIC defaults to NUMERIC(38, 9). When transpiling to DuckDB, the output DECIMAL without precision defaults to DECIMAL(18, 3), causing precision loss.
Fully reproducible code snippet
import sqlglot
result = sqlglot.transpile(
"SELECT CAST(x AS NUMERIC) FROM t",
read="bigquery",
write="duckdb"
)[0]
print(result)Output:
SELECT CAST(x AS DECIMAL) FROM tExpected:
SELECT CAST(x AS DECIMAL(38, 9)) FROM tWhy current output is wrong
BigQuery NUMERIC preserves 9 decimal places. DuckDB DECIMAL without precision defaults to 3 decimal places.
-- BigQuery:
SELECT CAST(1.123456789 AS NUMERIC);
-- Returns: 1.123456789
-- DuckDB with current transpilation:
SELECT CAST(1.123456789 AS DECIMAL);
-- Returns: 1.123 (precision loss)
-- DuckDB with expected transpilation:
SELECT CAST(1.123456789 AS DECIMAL(38, 9));
-- Returns: 1.123456789Official Documentation
Version
Tested on main (28.4.2.dev1)
Metadata
Metadata
Assignees
Labels
No labels