fix: preserve typmod for extension types in column type resolution (#295)#297
Merged
fix: preserve typmod for extension types in column type resolution (#295)#297
Conversation
) pgvector types with dimensions (e.g., vector(384), halfvec(384)) were losing their typmod during schema inspection. The resolved_type query only returned dt.typname for non-pg_catalog base types, dropping the typmod. Now extracts the typmod from format_type() and appends it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Greptile SummaryFixed pgvector dimension loss by extracting typmod from
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Column Type Resolution] --> B{Type Category?}
B -->|Domain/Enum/Composite| C[Use dt.typname with schema qualification]
B -->|Array Base Type| D["Use et.typname + [] with schema qualification"]
B -->|Non-Array Base Type| E{Schema Location?}
E -->|pg_catalog| F["Use c.udt_name (Standard types handled separately)"]
E -->|Same as table schema| G["dt.typname + extract typmod (Preserves vector(384))"]
E -->|Different schema| H["schema.dt.typname + extract typmod (Preserves dimensions)"]
G --> I["Typmod Extraction: substring(format_type FROM '([^)]*)')"]
H --> I
I --> J["Result: vector(384) or halfvec(384)"]
F --> K["Result: varchar or numeric (Dimensions stored in separate fields)"]
Last reviewed commit: 73f0244 |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes issue #295 where pgvector extension types with dimensions (e.g., vector(384), halfvec(384)) were losing their type modifiers (typmod) during schema inspection. The root cause was that the column type resolution query only returned the base type name (dt.typname) for non-pg_catalog types, without including the typmod information.
Changes:
- Modified SQL queries to extract typmod from
format_type(atttypid, atttypmod)using a POSIX regex pattern and append it to extension type names - Applied the fix consistently to both
GetColumnsandGetColumnsForSchemaqueries - Preserved existing schema qualification logic while adding typmod support for extension types
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
ir/queries/queries.sql |
Updated column type resolution logic in two queries (GetColumns and GetColumnsForSchema) to extract and preserve typmod for extension types using format_type() and regex extraction |
ir/queries/queries.sql.go |
Generated Go code from the updated SQL queries (auto-generated by sqlc) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add diff test case with setup.sql, old.sql, new.sql, and expected outputs for pgvector halfvec(384) column with HNSW index. The test is automatically skipped in CI since embedded-postgres doesn't include pgvector. Add skipListRequiresExtension mechanism for tests requiring third-party extensions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1c910b8 to
aab0e24
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vector(384),halfvec(384)) were losing their typmod during schema inspection because theresolved_typequery only returneddt.typnamefor non-pg_catalog base typesformat_type(atttypid, atttypmod)using a POSIX regex and appends it to the type name, preserving dimensions likevector(384)while maintaining existing schema qualification logicFixes #295
Test plan
go test ./...) — all packages greenadd_column_cross_schema_custom_type) passes — validates fix doesn't break existingcitext/hstorehandlinghalfvec(384)column and HNSW index, verifypgschema planpreserves dimensions🤖 Generated with Claude Code