Skip to content

Commit 25c815e

Browse files
authored
Merge pull request #29 from PostHog/fix/version-function-rewrite
Rewrite version() to return PostgreSQL-compatible string
2 parents 05e78d3 + ea8b3bc commit 25c815e

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)