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)
| 146 | // volatile expressions would be evaluated repeatedly; fine for the common |
| 147 | // literal/column case. |
| 148 | func (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 |
no test coverage detected