pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

pgvector typmod lost: vector/halfvec dimensions dropped in plan/apply, causing HNSW index failure ("column does not have dimensions")

Open KrisBraun opened this issue 9 months ago • 3 comments

Summary

When using pgvector types with dimensions (e.g., halfvec(384) / vector(384)), pgschema appears to drop the typmod during plan/apply. The generated plan SQL creates the column as halfvec (no dimensions). This causes CREATE INDEX ... hnsw to fail with ERROR: column does not have dimensions.

Reproduction

  1. Ensure pgvector extension is available:
CREATE EXTENSION IF NOT EXISTS vector;
  1. Desired state SQL (schema.sql):
CREATE TABLE activity (
  id bigserial PRIMARY KEY,
  embedding halfvec(384)
);

CREATE INDEX activity_embedding_idx
  ON activity USING hnsw (embedding halfvec_cosine_ops);
  1. Run pgschema:
pgschema apply --file schema.sql --schema public --auto-approve \
  --host localhost --db postgres --user postgres

Optional: pgschema plan --file schema.sql --output-sql plan.sql and inspect plan.sql.

Expected

  • Column is created as halfvec(384)
  • HNSW index is created successfully

Actual

  • Plan SQL creates column as halfvec (no dimensions)
  • Apply fails with:

ERROR: column does not have dimensions (SQLSTATE 22023)

at the HNSW index creation

Environment

  • pgschema 1.7.1 (github.com/pgplex/pgschema)
  • PostgreSQL 18.x (Docker)
  • pgvector enabled
  • macOS (darwin/arm64)

Additional Notes

It looks like typmod for pgvector types is being dropped somewhere in the IR or normalization. Happy to provide full plan SQL output if needed.

KrisBraun avatar Feb 17 '26 19:02 KrisBraun

Full plan SQL would be helpful

tianzhou avatar Feb 18 '26 17:02 tianzhou

Wow, incredible response time! Will run a full test later today. Truly grateful for you looking at this.

KrisBraun avatar Feb 19 '26 16:02 KrisBraun

Confirmed, the fix works.

KrisBraun avatar Feb 20 '26 03:02 KrisBraun