refactor(pkg): canonicalize base types and adjust length handling

* Update base types to keep explicit modifier forms
* Modify length handling for vector types in tests
This commit is contained in:
2026-04-26 17:35:15 +02:00
parent 4ca1810d07
commit ed7130bba8
7 changed files with 18 additions and 12 deletions

View File

@@ -1,6 +1,9 @@
package pgsql
import "strings"
import (
"sort"
"strings"
)
// TypeSpec describes PostgreSQL type capabilities used by parsers/writers.
type TypeSpec struct {
@@ -106,9 +109,9 @@ var postgresBaseTypes = map[string]TypeSpec{
"ltree": {},
"lquery": {},
"ltxtquery": {},
"vector": {SupportsLength: true}, // pgvector: vector(dim)
"halfvec": {SupportsLength: true}, // pgvector: halfvec(dim)
"sparsevec": {SupportsLength: true}, // pgvector: sparsevec(dim)
"vector": {}, // pgvector: keep explicit modifier form (vector(dim))
"halfvec": {}, // pgvector: keep explicit modifier form (halfvec(dim))
"sparsevec": {}, // pgvector: keep explicit modifier form (sparsevec(dim))
}
var postgresTypeAliases = map[string]string{
@@ -148,6 +151,7 @@ func GetPostgresBaseTypes() []string {
for t := range postgresBaseTypes {
result = append(result, t)
}
sort.Strings(result)
return result
}

View File

@@ -53,7 +53,7 @@ func TestPostgresTypeRegistry_TypeParsingAndCapabilities(t *testing.T) {
wantBase: "vector",
wantCanonicalBase: "vector",
wantKnown: true,
wantLength: true,
wantLength: false,
},
{
input: "numeric(10,2)",