Skip to content

Commit ea8b3bc

Browse files
EDsCODEclaude
andcommitted
Rewrite version() to return PostgreSQL-compatible string
PostgreSQL clients call SELECT version() to check database compatibility. DuckDB's native version() returns "v1.1.0 ..." which doesn't match PostgreSQL format and can't be overridden by macros. This rewrites version() calls to return a PostgreSQL-compatible string: "PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by gcc, 64-bit (Duckgres/DuckDB)" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 05e78d3 commit ea8b3bc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

server/catalog.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ var (
364364
showApplicationNameRegex = regexp.MustCompile(`(?i)^SHOW\s+application_name\s*;?\s*$`)
365365
// Regex to extract SET parameter name
366366
setParameterRegex = regexp.MustCompile(`(?i)^SET\s+(?:SESSION\s+|LOCAL\s+)?(\w+)`)
367+
// version() -> PostgreSQL-compatible version string (DuckDB's built-in can't be overridden by macro)
368+
versionFuncRegex = regexp.MustCompile(`(?i)\bversion\s*\(\s*\)`)
367369
)
368370

369371
// PostgreSQL-specific SET parameters that DuckDB doesn't support.
@@ -554,6 +556,10 @@ func rewritePgCatalogQuery(query string) string {
554556
query = setApplicationNameToRegex.ReplaceAllString(query, "SET VARIABLE application_name =")
555557
query = showApplicationNameRegex.ReplaceAllString(query, "SELECT getvariable('application_name') AS application_name")
556558

559+
// Replace version() with PostgreSQL-compatible version string
560+
// 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)'")
562+
557563
return query
558564
}
559565

0 commit comments

Comments
 (0)