writeCTEPrefix writes the statement's WITH (CTE) clause before the backup SELECT, so a SELECT whose FROM references a CTE stays valid. omni does not attach UPDATE/DELETE CTEs to the statement node, so the prefix is recovered from the text before the statement Loc.
(buf *strings.Builder, node ast.Node, fullSQL string)
| 429 | // attach UPDATE/DELETE CTEs to the statement node, so the prefix is recovered |
| 430 | // from the text before the statement Loc. |
| 431 | func writeCTEPrefix(buf *strings.Builder, node ast.Node, fullSQL string) error { |
| 432 | cte := extractCTE(fullSQL, nodeStmtLoc(node)) |
| 433 | if cte == "" { |
| 434 | return nil |
| 435 | } |
| 436 | _, err := fmt.Fprintf(buf, "%s ", cte) |
| 437 | return err |
| 438 | } |
| 439 | |
| 440 | // extractCTE returns the WITH-clause text preceding the statement, or "". |
| 441 | func extractCTE(fullSQL string, stmtLoc ast.Loc) string { |
no test coverage detected