File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,12 @@ var (
353353 regnamespaceCastRegex = regexp .MustCompile (`(?i)::pg_catalog\.regnamespace` )
354354 // ::pg_catalog.text -> ::VARCHAR
355355 textCastRegex = regexp .MustCompile (`(?i)::pg_catalog\.text` )
356+ // SET application_name = 'value' -> SET VARIABLE application_name = 'value'
357+ setApplicationNameRegex = regexp .MustCompile (`(?i)^SET\s+application_name\s*=` )
358+ // SET application_name TO 'value' -> SET VARIABLE application_name = 'value'
359+ setApplicationNameToRegex = regexp .MustCompile (`(?i)^SET\s+application_name\s+TO\s+` )
360+ // SHOW application_name -> SELECT getvariable('application_name') AS application_name
361+ showApplicationNameRegex = regexp .MustCompile (`(?i)^SHOW\s+application_name\s*;?\s*$` )
356362)
357363
358364// rewritePgCatalogQuery rewrites PostgreSQL-specific syntax for DuckDB compatibility
@@ -407,6 +413,11 @@ func rewritePgCatalogQuery(query string) string {
407413 query = regnamespaceCastRegex .ReplaceAllString (query , "::VARCHAR" )
408414 query = textCastRegex .ReplaceAllString (query , "::VARCHAR" )
409415
416+ // Replace PostgreSQL application_name with DuckDB variable
417+ query = setApplicationNameRegex .ReplaceAllString (query , "SET VARIABLE application_name =" )
418+ query = setApplicationNameToRegex .ReplaceAllString (query , "SET VARIABLE application_name =" )
419+ query = showApplicationNameRegex .ReplaceAllString (query , "SELECT getvariable('application_name') AS application_name" )
420+
410421 return query
411422}
412423
You can’t perform that action at this time.
0 commit comments