Skip to content

Commit 51d27be

Browse files
EDsCODEclaude
andcommitted
Fix SET application_name error by marking it as ignored
SET application_name requires SET VARIABLE syntax in DuckDB, but since it's only used for client identification (not critical functionality), mark it as ignored like other PostgreSQL-specific parameters. Also handle SHOW for ignored parameters by returning sensible defaults: - SHOW application_name -> SELECT 'duckgres' AS application_name - SHOW client_encoding -> SELECT 'UTF8' AS client_encoding - etc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 7aac83b commit 51d27be

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

transpiler/transform/setshow.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func NewSetShowTransform() *SetShowTransform {
3232
"idle_session_timeout": true,
3333

3434
// Client connection settings
35+
"application_name": true, // Used by clients for identification, not critical
3536
"client_min_messages": true,
3637
"log_min_messages": true,
3738
"log_min_duration_statement": true,
@@ -136,7 +137,8 @@ func NewSetShowTransform() *SetShowTransform {
136137
"wal_receiver_timeout": true,
137138
},
138139
VariableParams: map[string]bool{
139-
"application_name": true,
140+
// Parameters that need SET VARIABLE syntax in DuckDB
141+
// (currently none - application_name is ignored instead)
140142
},
141143
}
142144
}
@@ -181,7 +183,18 @@ func (t *SetShowTransform) Transform(tree *pg_query.ParseResult, result *Result)
181183
if n.VariableShowStmt != nil {
182184
paramName := strings.ToLower(n.VariableShowStmt.Name)
183185

184-
// Convert SHOW application_name to SELECT getvariable('application_name')
186+
// For ignored params, return a sensible default value
187+
if t.IgnoredParams[paramName] {
188+
defaultVal := t.getDefaultValue(paramName)
189+
selectStmt := t.createDefaultValueSelect(paramName, defaultVal)
190+
tree.Stmts[i].Stmt = &pg_query.Node{
191+
Node: &pg_query.Node_SelectStmt{SelectStmt: selectStmt},
192+
}
193+
changed = true
194+
continue
195+
}
196+
197+
// Convert SHOW to SELECT getvariable() for variable params
185198
if t.VariableParams[paramName] {
186199
// Replace with a SELECT statement
187200
selectStmt := t.createGetVariableSelect(paramName)
@@ -197,6 +210,48 @@ func (t *SetShowTransform) Transform(tree *pg_query.ParseResult, result *Result)
197210
return changed, nil
198211
}
199212

213+
// getDefaultValue returns a sensible default value for an ignored parameter
214+
func (t *SetShowTransform) getDefaultValue(paramName string) string {
215+
defaults := map[string]string{
216+
"application_name": "duckgres",
217+
"client_encoding": "UTF8",
218+
"statement_timeout": "0",
219+
"lock_timeout": "0",
220+
"extra_float_digits": "1",
221+
"transaction_isolation": "read committed",
222+
"synchronous_commit": "on",
223+
"work_mem": "4MB",
224+
}
225+
if val, ok := defaults[paramName]; ok {
226+
return val
227+
}
228+
return "" // Empty string for unknown params
229+
}
230+
231+
// createDefaultValueSelect creates a SELECT 'value' AS name statement
232+
func (t *SetShowTransform) createDefaultValueSelect(paramName, value string) *pg_query.SelectStmt {
233+
return &pg_query.SelectStmt{
234+
TargetList: []*pg_query.Node{
235+
{
236+
Node: &pg_query.Node_ResTarget{
237+
ResTarget: &pg_query.ResTarget{
238+
Name: paramName,
239+
Val: &pg_query.Node{
240+
Node: &pg_query.Node_AConst{
241+
AConst: &pg_query.A_Const{
242+
Val: &pg_query.A_Const_Sval{
243+
Sval: &pg_query.String{Sval: value},
244+
},
245+
},
246+
},
247+
},
248+
},
249+
},
250+
},
251+
},
252+
}
253+
}
254+
200255
// createGetVariableSelect creates a SELECT getvariable('name') AS name statement
201256
func (t *SetShowTransform) createGetVariableSelect(paramName string) *pg_query.SelectStmt {
202257
return &pg_query.SelectStmt{

transpiler/transpiler_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,26 @@ func TestTranspile_SetShow(t *testing.T) {
295295
}
296296
})
297297

298-
// Test SHOW application_name conversion
298+
// Test SHOW application_name returns default value
299299
t.Run("SHOW application_name", func(t *testing.T) {
300300
result, err := tr.Transpile("SHOW application_name")
301301
if err != nil {
302302
t.Fatalf("Transpile error: %v", err)
303303
}
304-
if !strings.Contains(strings.ToLower(result.SQL), "getvariable") {
305-
t.Errorf("SHOW application_name should be converted to getvariable, got: %q", result.SQL)
304+
// Should return SELECT 'duckgres' AS application_name
305+
if !strings.Contains(result.SQL, "duckgres") {
306+
t.Errorf("SHOW application_name should return default value 'duckgres', got: %q", result.SQL)
307+
}
308+
})
309+
310+
// Test SET application_name is ignored
311+
t.Run("SET application_name ignored", func(t *testing.T) {
312+
result, err := tr.Transpile("SET application_name = 'fivetran'")
313+
if err != nil {
314+
t.Fatalf("Transpile error: %v", err)
315+
}
316+
if !result.IsIgnoredSet {
317+
t.Error("SET application_name should be marked as ignored")
306318
}
307319
})
308320
}

0 commit comments

Comments
 (0)