Skip to content

fix: PostgreSQL dialect can not support tinyint type#21445

Open
xiedeyantu wants to merge 1 commit intoapache:mainfrom
xiedeyantu:smallint
Open

fix: PostgreSQL dialect can not support tinyint type#21445
xiedeyantu wants to merge 1 commit intoapache:mainfrom
xiedeyantu:smallint

Conversation

@xiedeyantu
Copy link
Copy Markdown
Member

Which issue does this PR close?

  • No linked issue.

Rationale for this change

DataFusion's PostgreSQL unparser should emit PostgreSQL-compatible SQL for integer casts.Int8 was still being rendered as TINYINT, which is not valid PostgreSQL syntax. This change makes PostgreSQL output SMALLINT instead.

What changes are included in this PR?

  • Added an int8_cast_dtype hook to the SQL unparser dialect abstraction.
  • Updated PostgreSqlDialect to map Int8 to SMALLINT.
  • Routed DataType::Int8 unparsing through the dialect hook.
  • Added a regression test covering select cast(3 as tinyint)] with PostgreSQL unparser output.

Are these changes tested?

  • Yes. Ran:
    • cargo test -p datafusion-sql --test sql_integration cases::plan_to_sql::test_cast_to_tinyint -- --exact
  • The test passes.

Are there any user-facing changes?

  • Yes. PostgreSQL dialect SQL generation now renders CAST(... AS SMALLINT) for Int8 values instead of CAST(... AS TINYINT).

@github-actions github-actions bot added the sql SQL Planner label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant