Skip to content

Commit c5e6cf0

Browse files
EDsCODEclaude
andcommitted
Fix version() column name to be 'version' not the literal string
When replacing version() with a string literal, the column name was the literal value instead of 'version'. This adds 'AS version' alias when needed, while preserving any existing alias. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 25c815e commit c5e6cf0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

server/catalog.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ var (
365365
// Regex to extract SET parameter name
366366
setParameterRegex = regexp.MustCompile(`(?i)^SET\s+(?:SESSION\s+|LOCAL\s+)?(\w+)`)
367367
// version() -> PostgreSQL-compatible version string (DuckDB's built-in can't be overridden by macro)
368-
versionFuncRegex = regexp.MustCompile(`(?i)\bversion\s*\(\s*\)`)
368+
// Two patterns: one for version() with existing AS alias, one for version() without
369+
versionFuncWithAliasRegex = regexp.MustCompile(`(?i)\bversion\s*\(\s*\)(\s+AS\s+)`)
370+
versionFuncRegex = regexp.MustCompile(`(?i)\bversion\s*\(\s*\)`)
369371
)
370372

371373
// PostgreSQL-specific SET parameters that DuckDB doesn't support.
@@ -558,7 +560,10 @@ func rewritePgCatalogQuery(query string) string {
558560

559561
// Replace version() with PostgreSQL-compatible version string
560562
// DuckDB's built-in version() can't be overridden by macros
561-
query = versionFuncRegex.ReplaceAllString(query, "'PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc, 64-bit (Duckgres/DuckDB)'")
563+
// First handle version() with existing AS alias (preserve the alias)
564+
query = versionFuncWithAliasRegex.ReplaceAllString(query, "'PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc, 64-bit (Duckgres/DuckDB)'$1")
565+
// Then handle remaining version() calls (add AS version alias)
566+
query = versionFuncRegex.ReplaceAllString(query, "'PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc, 64-bit (Duckgres/DuckDB)' AS version")
562567

563568
return query
564569
}

0 commit comments

Comments
 (0)