pgvector typmod lost: vector/halfvec dimensions dropped in plan/apply, causing HNSW index failure ("column does not have dimensions")
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
- Ensure pgvector extension is available:
CREATE EXTENSION IF NOT EXISTS vector;
- 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);
- 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.
Full plan SQL would be helpful
Wow, incredible response time! Will run a full test later today. Truly grateful for you looking at this.
Confirmed, the fix works.