expandUpdateStmt expands * in an UPDATE statement's RETURNING clause
(ctx context.Context, stmt *ast.UpdateStmt)
| 238 | |
| 239 | // expandUpdateStmt expands * in an UPDATE statement's RETURNING clause |
| 240 | func (e *Expander) expandUpdateStmt(ctx context.Context, stmt *ast.UpdateStmt) error { |
| 241 | // Expand CTEs first |
| 242 | if stmt.WithClause != nil && stmt.WithClause.Ctes != nil { |
| 243 | for _, cte := range stmt.WithClause.Ctes.Items { |
| 244 | if err := e.expandNode(ctx, cte); err != nil { |
| 245 | return err |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // Expand RETURNING clause |
| 251 | if hasStarInList(stmt.ReturningList) { |
| 252 | tempRaw := &ast.RawStmt{Stmt: stmt} |
| 253 | tempQuery := ast.Format(tempRaw, e.dialect) |
| 254 | columns, err := e.getColumnNames(ctx, tempQuery) |
| 255 | if err != nil { |
| 256 | return fmt.Errorf("failed to get column names: %w", err) |
| 257 | } |
| 258 | stmt.ReturningList = rewriteTargetList(stmt.ReturningList, columns) |
| 259 | } |
| 260 | |
| 261 | return nil |
| 262 | } |
| 263 | |
| 264 | // expandDeleteStmt expands * in a DELETE statement's RETURNING clause |
| 265 | func (e *Expander) expandDeleteStmt(ctx context.Context, stmt *ast.DeleteStmt) error { |
no test coverage detected