Skip to content

Commit 85dc1a7

Browse files
authored
Pass through DuckDB SHOW commands (TABLES, DATABASES, ALL) (#268)
SHOW TABLES, SHOW DATABASES, and SHOW ALL were being rejected with "unrecognized configuration parameter" because the transpiler's catch-all treated any single-word SHOW argument as a PostgreSQL config parameter. These are valid DuckDB commands that return result sets and should be forwarded to DuckDB unchanged.
1 parent 9c6d374 commit 85dc1a7

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

transpiler/transform/setshow.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import (
1212
// (lowercase letters, digits, and underscores, starting with a letter)
1313
var configParamPattern = regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
1414

15+
// duckdbShowCommands are DuckDB-specific SHOW commands that should be passed
16+
// through to DuckDB rather than treated as PostgreSQL config parameters.
17+
var duckdbShowCommands = map[string]bool{
18+
"tables": true,
19+
"databases": true,
20+
"all": true,
21+
}
22+
1523
// SetShowTransform handles SET and SHOW commands:
1624
// - SET application_name = 'x' -> SET VARIABLE application_name = 'x'
1725
// - SHOW application_name -> SELECT getvariable('application_name') AS application_name
@@ -277,6 +285,13 @@ func (t *SetShowTransform) Transform(tree *pg_query.ParseResult, result *Result)
277285
continue
278286
}
279287

288+
// DuckDB SHOW commands (SHOW TABLES, SHOW DATABASES, SHOW ALL TABLES)
289+
// are parsed as VariableShowStmt by pg_query but should be passed
290+
// through to DuckDB as-is.
291+
if duckdbShowCommands[paramName] {
292+
continue
293+
}
294+
280295
// If this looks like a PostgreSQL config parameter (e.g., "some_setting")
281296
// but we don't recognize it, return an error rather than letting DuckDB
282297
// give a confusing "table not found" error

transpiler/transpiler_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,46 @@ func TestTranspile_SetShow(t *testing.T) {
690690
}
691691
})
692692

693+
// Test DuckDB SHOW commands pass through unchanged
694+
t.Run("SHOW TABLES passthrough", func(t *testing.T) {
695+
result, err := tr.Transpile("SHOW TABLES")
696+
if err != nil {
697+
t.Fatalf("Transpile error: %v", err)
698+
}
699+
if result.Error != nil {
700+
t.Fatalf("SHOW TABLES should not error, got: %v", result.Error)
701+
}
702+
if !strings.Contains(strings.ToUpper(result.SQL), "SHOW TABLES") {
703+
t.Errorf("SHOW TABLES should pass through, got: %q", result.SQL)
704+
}
705+
})
706+
707+
t.Run("SHOW DATABASES passthrough", func(t *testing.T) {
708+
result, err := tr.Transpile("SHOW DATABASES")
709+
if err != nil {
710+
t.Fatalf("Transpile error: %v", err)
711+
}
712+
if result.Error != nil {
713+
t.Fatalf("SHOW DATABASES should not error, got: %v", result.Error)
714+
}
715+
if !strings.Contains(strings.ToUpper(result.SQL), "SHOW DATABASES") {
716+
t.Errorf("SHOW DATABASES should pass through, got: %q", result.SQL)
717+
}
718+
})
719+
720+
t.Run("SHOW ALL passthrough", func(t *testing.T) {
721+
result, err := tr.Transpile("SHOW ALL")
722+
if err != nil {
723+
t.Fatalf("Transpile error: %v", err)
724+
}
725+
if result.Error != nil {
726+
t.Fatalf("SHOW ALL should not error, got: %v", result.Error)
727+
}
728+
if !strings.Contains(strings.ToUpper(result.SQL), "SHOW ALL") {
729+
t.Errorf("SHOW ALL should pass through, got: %q", result.SQL)
730+
}
731+
})
732+
693733
// Test SET application_name is ignored
694734
t.Run("SET application_name ignored", func(t *testing.T) {
695735
result, err := tr.Transpile("SET application_name = 'fivetran'")

0 commit comments

Comments
 (0)