Skip to content

Commit a6797e9

Browse files
committed
fix: prioritize exact SQL file match
1 parent 64abf7b commit a6797e9

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

regresql/planwalk.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func findSQLFileAndQuery(sqlDir, planBase string) (string, string, error) {
101101
return "", "", fmt.Errorf("cannot read SQL directory %s: %w", sqlDir, err)
102102
}
103103

104+
// First pass: check for exact match (higher priority)
104105
for _, entry := range entries {
105106
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".sql") {
106107
continue
@@ -112,8 +113,16 @@ func findSQLFileAndQuery(sqlDir, planBase string) (string, string, error) {
112113
if planBase == sqlBase {
113114
return entry.Name(), sqlBase, nil
114115
}
116+
}
117+
118+
// Second pass: check for prefix match (multi-query files: sqlbase_queryname)
119+
for _, entry := range entries {
120+
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".sql") {
121+
continue
122+
}
123+
124+
sqlBase := strings.TrimSuffix(entry.Name(), ".sql")
115125

116-
// Check for prefix match (multi-query files: sqlbase_queryname)
117126
prefix := sqlBase + "_"
118127
if strings.HasPrefix(planBase, prefix) {
119128
queryName := strings.TrimPrefix(planBase, prefix)

0 commit comments

Comments
 (0)