Skip to content

fix(postgres): register pgvector types#809

Merged
kvch merged 4 commits into
xataio:mainfrom
rieg-ec:codex/register-pgvector-types
Jun 1, 2026
Merged

fix(postgres): register pgvector types#809
kvch merged 4 commits into
xataio:mainfrom
rieg-ec:codex/register-pgvector-types

Conversation

@rieg-ec
Copy link
Copy Markdown
Contributor

@rieg-ec rieg-ec commented May 11, 2026

Description

came across this issue when using pgstream with a database that uses vector extension with a custom size # embedding :vector(3072)

i patched the pgstream pg_utils.go to call pgxvec.RegisterTypes and it worked. Without this, pgx does not know how to encode/decode pgvector values and Postgres targets can fail when a replicated table contains vector columns.

not sure if this is the right place to do it, it was highly vibecoded, but it seemed to work for us so i'll let this PR in case it's useful

Related Issue(s)
  • Related to pgvector extension support

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

  • Register pgvector types through github.com/pgvector/pgvector-go/pgx in the shared Postgres connection type setup.
  • Ignore the expected vector type not found registration error when the extension is not installed.
  • Add unit coverage for the pgvector registration error handling.

Testing

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

Commands run:

go test ./internal/postgres
go test ./...

Checklist

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

Additional Notes

Comment thread internal/postgres/pg_utils.go Outdated
})
}

if err := handlePgvectorRegisterTypesErr(pgxvec.RegisterTypes(ctx, conn)); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please refactor these lines to be similar to what we do for the extension hstore?

Something along the lines of:

 var vectorOID uint32
  if err := conn.QueryRow(ctx, "SELECT to_regtype('vector')::oid").Scan(&vectorOID); err == nil && vectorOID != 0 {
      if err := pgxvec.RegisterTypes(ctx, conn); err != nil {
          return fmt.Errorf("registering pgvector types: %w", err)
      }
  }

Copy link
Copy Markdown
Collaborator

@kvch kvch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. Asking for a small refactoring.

@kvch kvch merged commit 55f319a into xataio:main Jun 1, 2026
7 of 8 checks passed
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