Skip to content

Convert JSON constructor arguments the way PostgreSQL does - #176

Merged
LucaCappelletti94 merged 4 commits into
mainfrom
upstream/json-functions-over-blob
Oct 29, 2026
Merged

LucaCappelletti94 merged 4 commits into
mainfrom
upstream/json-functions-over-blob

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Collaborator

json_agg, json_build_array, json_build_object, to_json and json_object_agg hand SQLite the stored value of each argument, and SQLite's JSON functions encode that value as they find it. Wherever pg2sqlite stores a type as something other than PostgreSQL's value, the answer differs. A bytea column, or a uuid under UuidRepresentation::Blob, fails with JSON cannot hold BLOB values. A boolean comes out as 1, a NUMERIC(10,2) as its minor units, a timestamp without the ISO T, a json column inside json_build_array as a quoted string, and a timetz offset keeps its :00.

Every argument of these constructors and their jsonb forms goes through one conversion in json_value.rs, chosen from the argument's declared or written type, so the constructors cannot drift apart again. Object keys take the value's JSON text, as PostgreSQL's do, and a JSON document used as a key is refused because PostgreSQL refuses it. A vector, a geometry or another extension type stored as a BLOB has no text form in SQL, so it is refused at translation rather than failing in SQLite at run time. A bare column whose table is outside the translation batch is refused by every constructor, as to_json and json_agg already refused it, since the conversion depends on its type.

The new gauntlet test runs each constructor over every type on PostgreSQL 18 and on the translation, and compares the two through jsonb. CI needs #174 first, because sqlparser main added Statement::RevokeRole.

@LucaCappelletti94 LucaCappelletti94 added the bug Something isn't working label Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LucaCappelletti94
LucaCappelletti94 merged commit 98a68b0 into main Oct 29, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant