Skip to content

feat(duckdb): Add transpilation support for SPACE function#6867

Merged
georgesittas merged 1 commit into
mainfrom
RD-1147757-space
Jan 27, 2026
Merged

feat(duckdb): Add transpilation support for SPACE function#6867
georgesittas merged 1 commit into
mainfrom
RD-1147757-space

Conversation

@fivetran-amrutabhimsenayachit
Copy link
Copy Markdown
Collaborator

The transpilation of SPACE() to REPEAT() fails in DuckDB when the input argument is a FLOAT or DECIMAL type because DuckDB's REPEAT() function strictly requires the second argument (repeat count) to be of type BIGINT. SQLGlot currently transpiles SPACE(n) to REPEAT(' ', n) without adding the necessary type cast, causing runtime errors.
Fix: Added a custom space_sql method in the DuckDB dialect to wrap the count argument with CAST to BIGINT.

After Fix:

 python3 -c "import sqlglot; print(sqlglot.transpile(\"SELECT SPACE(5) AS space_integer, SPACE(3.7) AS space_float, SPACE(CAST(4.9 AS DECIMAL(10,2))) AS space_decimal, SPACE(0) AS space_zero, SPACE(NULL) AS space_null\", read='snowflake', write='duckdb')[0])" | duckdb
┌───────────────┬─────────────┬───────────────┬────────────┬────────────┐
│ space_integer │ space_float │ space_decimal │ space_zero │ space_null │
│    varchar    │   varchar   │    varchar    │  varchar   │  varchar   │
├───────────────┼─────────────┼───────────────┼────────────┼────────────┤
│               │             │               │            │ NULL       │
└───────────────┴─────────────┴───────────────┴────────────┴────────────┘

@github-actions
Copy link
Copy Markdown
Contributor

SQLGlot Integration Test Results

Comparing:

  • this branch (sqlglot:RD-1147757-space, sqlglot version: RD-1147757-space)
  • baseline (main, sqlglot version: 28.6.1.dev103)

⚠️ Limited to dialects: snowflake, duckdb

By Dialect

dialect main sqlglot:RD-1147757-space difference links
duckdb -> duckdb 4003/4003 passed (100.0%) 4003/4003 passed (100.0%) No change full result / delta
snowflake -> duckdb 870/1481 passed (58.7%) 872/1481 passed (58.9%) ⬆ improved by 0.1% full result / delta
snowflake -> snowflake 1473/1481 passed (99.5%) 1473/1481 passed (99.5%) No change full result / delta

Overall

main: 6965 total, 6346 passed (pass rate: 91.1%), sqlglot version: 28.6.1.dev103

sqlglot:RD-1147757-space: 6965 total, 6348 passed (pass rate: 91.1%), sqlglot version: RD-1147757-space

Difference: No change

@georgesittas georgesittas merged commit bf90b5d into main Jan 27, 2026
9 checks passed
@georgesittas georgesittas deleted the RD-1147757-space branch January 27, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants