MCPcopy Create free account
hub / github.com/PostHog/duckgres / rewriteOverlay

Method rewriteOverlay

transpiler/transform/functions_compat.go:148–163  ·  view source on GitHub ↗

rewriteOverlay rewrites overlay(s placing repl from start [for len]) into substr(s,1,start-1) || repl || substr(s, start+len). Default len = length(repl). s, start and (in the FROM-only form) repl are each referenced more than once — volatile expressions would be evaluated repeatedly; fine for the c

(node *pg_query.Node, fc *pg_query.FuncCall)

Source from the content-addressed store, hash-verified

146// volatile expressions would be evaluated repeatedly; fine for the common
147// literal/column case.
148func (t *FunctionTransform) rewriteOverlay(node *pg_query.Node, fc *pg_query.FuncCall) bool {
149 if len(fc.Args) < 3 {
150 return false
151 }
152 s, repl, start := fc.Args[0], fc.Args[1], fc.Args[2]
153 var length *pg_query.Node
154 if len(fc.Args) >= 4 {
155 length = fc.Args[3]
156 } else {
157 length = funcCallNode("length", repl)
158 }
159 left := funcCallNode("substr", s, intConstNode(1), binExprNode("-", start, intConstNode(1)))
160 right := funcCallNode("substr", s, binExprNode("+", start, length))
161 node.Node = concatNodes([]*pg_query.Node{left, repl, right}).Node
162 return true
163}
164
165// rewriteIsfiniteInterval replaces isfinite(<interval>) with TRUE, supplying the
166// INTERVAL overload DuckDB lacks. Only fires when the argument is provably an

Callers 1

replaceCompatFuncNodeMethod · 0.95

Calls 4

funcCallNodeFunction · 0.85
intConstNodeFunction · 0.85
binExprNodeFunction · 0.85
concatNodesFunction · 0.85

Tested by

no test coverage detected