Skip to content

Fix update failres on generated columns#820

Merged
tsg merged 2 commits into
mainfrom
fix_generated_columns_updates
May 20, 2026
Merged

Fix update failres on generated columns#820
tsg merged 2 commits into
mainfrom
fix_generated_columns_updates

Conversation

@tsg
Copy link
Copy Markdown
Member

@tsg tsg commented May 20, 2026

Description

PR #754 introduced a regression for replicating updates on GENERATED ALWAYS AS IDENTITY columns. It was meant to avoid generating identity columns on the target, so that FKs stay valid. But INSERT and UPDATE share the same filterRowColumns path, so any UPDATE that includes an always-identity column in the SET clause is rejected by Postgres.

The fix is that buildUpdateQuery now calls filterRowColumnsForAction(..., forUpdate=true), which additionally drops always-identity columns from the SET clause. INSERT, bulk INSERT, and COPY paths are untouched.

Added more tests to cover more of the scenarios. Current state is:

Fixes #821.

Scenario Coverage
1. Snapshot, empty cache (SQL path) Test_SnapshotToPostgres_IdentityOnlyTable (real coverage via #754's path)
2. Live INSERT, DDL path Test_PostgresToPostgres_IdentityColumns (real coverage)
3. Live UPDATE on always-identity, DDL path Test_PostgresToPostgres_AlwaysIdentityUpdate (integration smoke; UPDATE is filtered via the existing generatedColumns path, so it passes either way — the new filter is dead code in this integration test)
4. Live UPDATE on always-identity, SQL path ⚠️ Unit tests only (TestDMLAdapter_walDataToQueries with empty generatedColumns + populated alwaysIdentityColumns) — integration coverage isn't feasible without dismantling TestMain's DDL-trigger install

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

Changes Made

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Code is well-commented
  • Documentation updated where necessary

Additional Notes

@tsg tsg enabled auto-merge (squash) May 20, 2026 16:42
@tsg tsg merged commit 9eaba98 into main May 20, 2026
7 checks passed
@tsg tsg deleted the fix_generated_columns_updates branch May 20, 2026 16:44
@github-actions
Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/pkg/stream/integration 0.00% (ø)
github.com/xataio/pgstream/pkg/wal 71.65% (-0.57%) 👎
github.com/xataio/pgstream/pkg/wal/processor/postgres 79.25% (-1.26%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_schema_observer.go 74.45% (-7.53%) 137 (+26) 102 (+11) 35 (+15) 👎
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_adapter.go 73.08% (-0.84%) 52 (+6) 38 (+4) 14 (+2) 👎
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_dml_adapter.go 95.00% (+0.16%) 160 (+5) 152 (+5) 8 👍
github.com/xataio/pgstream/pkg/wal/wal_ddl.go 69.39% (-1.45%) 49 (+1) 34 15 (+1) 👎

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/stream/integration/pg_pg_integration_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/helper_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_schema_observer_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_dml_adapter_test.go

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.

Error rule violation: column can only be updated to DEFAULT on v0.9.11

2 participants