Skip to content

Unparse named_struct as a function call for dialects without dictionary syntax - #78

Open
MRoci wants to merge 2 commits into
friendlymatthew/pydantic-main-df55from
fix-named-struct-unparse-postgres
Open

MRoci wants to merge 2 commits into
friendlymatthew/pydantic-main-df55from
fix-named-struct-unparse-postgres

Conversation

@MRoci

@MRoci MRoci commented Sep 23, 2026

Copy link
Copy Markdown

The unparser renders named_struct as a DuckDB-style dictionary literal ({"a": 1}) for every dialect (named_struct_to_sql in unparser/expr.rs), but the postgres, MySQL, SQLite and BigQuery parsers reject that syntax, so unparsed SQL containing named_struct fails to re-parse under the same dialect it was unparsed for.

Adds Dialect::supports_dictionary_syntax() (default true, matching the dialects whose parsers accept the literal) and falls back to a plain named_struct(...) function call otherwise, which survives the round trip. The check sits inside named_struct_to_sql so the get_field compound-access path at expr.rs:796, which bypasses dialect overrides, is covered too.

Includes a parse -> plan -> unparse -> re-parse test; the full sql_integration suite (573) and lib unparser tests (37) pass, and default-dialect output is unchanged.

Upstream PR to apache/datafusion to follow; this carries the fix until it lands there.

@github-actions github-actions Bot added the sql label Sep 23, 2026
Comment thread datafusion/sql/src/unparser/expr.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants