expandDeleteStmt expands * in a DELETE statement's RETURNING clause
(ctx context.Context, stmt *ast.DeleteStmt)
| 263 | |
| 264 | // expandDeleteStmt expands * in a DELETE statement's RETURNING clause |
| 265 | func (e *Expander) expandDeleteStmt(ctx context.Context, stmt *ast.DeleteStmt) error { |
| 266 | // Expand CTEs first |
| 267 | if stmt.WithClause != nil && stmt.WithClause.Ctes != nil { |
| 268 | for _, cte := range stmt.WithClause.Ctes.Items { |
| 269 | if err := e.expandNode(ctx, cte); err != nil { |
| 270 | return err |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | // Expand RETURNING clause |
| 276 | if hasStarInList(stmt.ReturningList) { |
| 277 | tempRaw := &ast.RawStmt{Stmt: stmt} |
| 278 | tempQuery := ast.Format(tempRaw, e.dialect) |
| 279 | columns, err := e.getColumnNames(ctx, tempQuery) |
| 280 | if err != nil { |
| 281 | return fmt.Errorf("failed to get column names: %w", err) |
| 282 | } |
| 283 | stmt.ReturningList = rewriteTargetList(stmt.ReturningList, columns) |
| 284 | } |
| 285 | |
| 286 | return nil |
| 287 | } |
| 288 | |
| 289 | // expandFromClause expands * in subqueries within FROM clause |
| 290 | func (e *Expander) expandFromClause(ctx context.Context, node ast.Node) error { |
no test coverage detected