Skip to content

Fix JSONB string scalar serialization#744

Merged
tsg merged 1 commit intov0.9.xfrom
fix_jsonb_scalar_values
Mar 3, 2026
Merged

Fix JSONB string scalar serialization#744
tsg merged 1 commit intov0.9.xfrom
fix_jsonb_scalar_values

Conversation

@tsg
Copy link
Member

@tsg tsg commented Mar 2, 2026

Description

serializeJSONBValue did not handle Go string values for jsonb/json columns. When pgx unmarshals a JSON string scalar like "FIRST", it returns a bare Go string without JSON quotes. This was passed through to CopyFrom unchanged, causing PostgreSQL to reject it as invalid JSON.

Add a string case that JSON-encodes values not already valid JSON, while preserving passthrough for pre-built JSON documents.

NOTE: opened against 0.9.x, we need to merge 0.9.x into main after releasing.

Related Issue(s)

Type of Change

Please select the relevant option(s):

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔨 Build/CI changes
  • 🧹 Code cleanup

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/pkg/wal/processor/postgres 83.83% (+0.06%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_dml_adapter.go 94.74% (+0.11%) 152 (+3) 144 (+3) 8 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/xataio/pgstream/pkg/wal/processor/postgres/jsonb_serialization_test.go

@tsg tsg merged commit e8c9325 into v0.9.x Mar 3, 2026
13 of 14 checks passed
@tsg tsg deleted the fix_jsonb_scalar_values branch March 3, 2026 09:23
tsg added a commit that referenced this pull request Mar 5, 2026
* Use IS NULL when building update query WHERE clause

* Add unit test for delete

* Enabled coverage for v0.9.x

* Fix cleanup restore failing on missing relations during DROP TRIGGER (#742)

* Fix JSONB string scalar serialization (#744)

---------

Co-authored-by: eminano <esther@xata.io>
@tsg tsg mentioned this pull request Mar 19, 2026
13 tasks
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