Skip to content

codegen/golang: fix pgvector pointer type for NOT NULL and arrays - #4732

Open
dhanush0x96c wants to merge 1 commit into
sqlc-dev:mainfrom
dhanush0x96c:fix/pgvector-not-null-pointer
Open

dhanush0x96c wants to merge 1 commit into
sqlc-dev:mainfrom
dhanush0x96c:fix/pgvector-not-null-pointer

Conversation

@dhanush0x96c

Copy link
Copy Markdown

Summary

Fixes postgresType in internal/codegen/golang/postgresql_type.go so that vector columns with pgx/v5 and emit_pointers_for_null_types: true check !notNull before returning *pgvector.Vector.

Previously, postgresType returned *pgvector.Vector whenever emitPointersForNull was true, ignoring notNull (col.NotNull || col.IsArray). As a result:

  • NOT NULL vector columns generated *pgvector.Vector instead of pgvector.Vector.
  • vector[] array columns generated []*pgvector.Vector instead of []pgvector.Vector.

Changes

  • internal/codegen/golang/postgresql_type.go: Added && !notNull to the emitPointersForNull check in the "vector" case of postgresType and removed the redundant else branch.
  • internal/endtoend/testdata/pg_vector/postgresql/pgx_emit_pointers_for_null_types/: Added an end-to-end test case (base context with invalid_schema: true, matching pg_vector/postgresql/pgx) covering nullable vector(3) (*pgvector.Vector), NOT NULL vector(3) (pgvector.Vector), and vector(3)[] ([]pgvector.Vector).

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.

1 participant