Skip to content

Parse CASE expressions returning JSON as JSON columns - #1704

Open
lee3Q wants to merge 3 commits into
sqlpage:mainfrom
lee3Q:fix/case-json-columns
Open

lee3Q wants to merge 3 commits into
sqlpage:mainfrom
lee3Q:fix/case-json-columns

Conversation

@lee3Q

@lee3Q lee3Q commented Dec 4, 2026

Copy link
Copy Markdown

Fixes #1703

A column such as CASE WHEN cond THEN json_object(...) ELSE NULL END AS item was not recognised as a JSON column, so the columns component received it as text and printed the JSON string. A bare json_object(...) was already handled.

is_json_expression now looks through parentheses, and treats a CASE expression as JSON when at least one branch is a JSON expression and every other branch is JSON or a NULL literal. A CASE that mixes JSON with other values is left as it was.

Tests:

  • a unit test in projection_partitioning.rs for the detection (JSON with ELSE NULL, parenthesised CASE without ELSE, text with NULL, JSON mixed with text);
  • a component_rendering SQL file with a CASE item. It contains the word "error" inside an unused key, so it fails if the JSON is printed as text. It fails on the previous code and passes with this change.

Also added a CHANGELOG entry.

Run on SQLite: cargo test --lib (256 passed), the sql_test_files tests, cargo fmt --check and cargo clippy --all-targets. Other databases were not run.

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.

Malformatted json when in a test

1 participant