Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ func functionReferencesNewView(fn *ir.Function, newViews map[string]struct{}) bo
}

// extractBaseTypeName extracts the base type name from a type expression,
// stripping SETOF prefix and array notation.
// stripping SETOF prefix, array notation, and double quotes from identifiers.
func extractBaseTypeName(typeExpr string) string {
t := strings.TrimSpace(typeExpr)
// Strip SETOF prefix (case-insensitive)
Expand All @@ -1940,6 +1940,8 @@ func extractBaseTypeName(typeExpr string) string {
for len(t) > 2 && t[len(t)-2:] == "[]" {
t = t[:len(t)-2]
}
// Strip double quotes from identifiers (e.g., public."ViewName" -> public.ViewName)
t = strings.ReplaceAll(t, "\"", "")
return t
}

Expand Down
61 changes: 61 additions & 0 deletions internal/diff/type_extract_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package diff

import "testing"

func TestExtractBaseTypeName(t *testing.T) {
tests := []struct {
name string
typeExpr string
want string
}{
{
name: "simple type",
typeExpr: "integer",
want: "integer",
},
{
name: "SETOF simple type",
typeExpr: "SETOF actor",
want: "actor",
},
{
name: "SETOF with schema",
typeExpr: "SETOF public.actor",
want: "public.actor",
},
{
name: "SETOF with quoted type name",
typeExpr: `SETOF public."ViewName"`,
want: "public.ViewName",
},
{
name: "SETOF with quoted schema and type",
typeExpr: `SETOF "Schema"."ViewName"`,
want: "Schema.ViewName",
},
{
name: "quoted type only",
typeExpr: `"MyType"`,
want: "MyType",
},
{
name: "array type",
typeExpr: "integer[]",
want: "integer",
},
{
name: "SETOF quoted type with array",
typeExpr: `SETOF public."ViewName"[]`,
want: "public.ViewName",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := extractBaseTypeName(tt.typeExpr)
if got != tt.want {
t.Errorf("extractBaseTypeName(%q) = %q, want %q", tt.typeExpr, got, tt.want)
}
})
}
}
Loading