Skip to content

Commit

Permalink
Add set_config() support
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunlol committed Dec 13, 2024
1 parent 3930a84 commit ed640f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func TestHandleQuery(t *testing.T) {
"SELECT pg_catalog.pg_get_expr(adbin, drelid, TRUE) AS def_value FROM pg_catalog.pg_attrdef": {
"description": {"def_value"},
},
"SELECT set_config('bytea_output', 'hex', false)": {
"description": {"set_config"},
"values": {"hex"},
},
// PG system tables
"SELECT oid, typname AS typename FROM pg_type WHERE typname='geometry' OR typname='geography'": {
"description": {"oid", "typename"},
Expand Down
16 changes: 16 additions & 0 deletions src/query_parser_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
const (
PG_FUNCTION_QUOTE_INDENT = "quote_ident"
PG_FUNCTION_PG_GET_EXPR = "pg_get_expr"
PG_FUNCTION_SET_CONFIG = "set_config"
)

type QueryParserSelect struct {
Expand Down Expand Up @@ -68,6 +69,21 @@ func (parser *QueryParserSelect) RemoveThirdArgumentFromPgGetExpr(functionCall *
return functionCall
}

// set_config()
func (parser *QueryParserSelect) IsSetConfigFunction(functionName string) bool {
return functionName == PG_FUNCTION_SET_CONFIG
}

// set_config(setting_name, new_value, is_local) -> new_value
func (parser *QueryParserSelect) RemapSetConfigFunction(targetNode *pgQuery.Node, functionCall *pgQuery.FuncCall) {
valueNode := functionCall.Args[1]
settingName := functionCall.Args[0].GetAConst().GetSval().Sval
LogWarn(parser.config, "Unsupported set_config", settingName, ":", functionCall)

parser.OverrideTargetValue(targetNode, valueNode)
parser.SetDefaultTargetName(targetNode, PG_FUNCTION_SET_CONFIG)
}

func (parser *QueryParserSelect) OverrideFunctionCallArg(functionCall *pgQuery.FuncCall, index int, node *pgQuery.Node) {
functionCall.Args[index] = node
}
Expand Down
5 changes: 5 additions & 0 deletions src/select_remapper_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func (remapper *SelectRemapperSelect) RemapSelect(targetNode *pgQuery.Node) *pgQ

originalFunctionName := remapper.parserSelect.FunctionName(functionCall)

if remapper.parserSelect.IsSetConfigFunction(originalFunctionName) {
remapper.parserSelect.RemapSetConfigFunction(targetNode, functionCall)
return targetNode
}

renamedNameFunction := remapper.remappedFunctionName(functionCall)
if renamedNameFunction != nil {
functionCall = renamedNameFunction
Expand Down

0 comments on commit ed640f7

Please sign in to comment.