(n *pcast.DeleteStmt)
| 328 | } |
| 329 | |
| 330 | func (c *cc) convertDeleteStmt(n *pcast.DeleteStmt) *ast.DeleteStmt { |
| 331 | stmt := &ast.DeleteStmt{ |
| 332 | WhereClause: c.convert(n.Where), |
| 333 | ReturningList: &ast.List{}, |
| 334 | WithClause: c.convertWithClause(n.With), |
| 335 | } |
| 336 | |
| 337 | if n.Limit != nil { |
| 338 | stmt.LimitCount = c.convert(n.Limit.Count) |
| 339 | } |
| 340 | |
| 341 | // Handle multi-table DELETE (DELETE t1, t2 FROM t1 JOIN t2 ...) |
| 342 | if n.IsMultiTable && n.Tables != nil && len(n.Tables.Tables) > 0 { |
| 343 | // Convert delete targets (e.g., jt.*, pt.*) |
| 344 | targets := &ast.List{} |
| 345 | for _, table := range n.Tables.Tables { |
| 346 | // Each table in the delete list is a ColumnRef like "jt.*" or "pt.*" |
| 347 | items := []ast.Node{} |
| 348 | if table.Schema.String() != "" { |
| 349 | items = append(items, NewIdentifier(table.Schema.String())) |
| 350 | } |
| 351 | items = append(items, NewIdentifier(table.Name.String())) |
| 352 | items = append(items, &ast.A_Star{}) |
| 353 | targets.Items = append(targets.Items, &ast.ColumnRef{ |
| 354 | Fields: &ast.List{Items: items}, |
| 355 | }) |
| 356 | } |
| 357 | stmt.Targets = targets |
| 358 | |
| 359 | // Convert FROM clause preserving JOINs |
| 360 | if n.TableRefs != nil { |
| 361 | fromList := c.convertTableRefsClause(n.TableRefs) |
| 362 | if len(fromList.Items) == 1 { |
| 363 | stmt.FromClause = fromList.Items[0] |
| 364 | } else { |
| 365 | stmt.FromClause = fromList |
| 366 | } |
| 367 | } |
| 368 | } else { |
| 369 | // Single-table DELETE |
| 370 | rels := c.convertTableRefsClause(n.TableRefs) |
| 371 | if len(rels.Items) != 1 { |
| 372 | panic("expected one range var") |
| 373 | } |
| 374 | relations := &ast.List{} |
| 375 | convertToRangeVarList(rels, relations) |
| 376 | stmt.Relations = relations |
| 377 | } |
| 378 | |
| 379 | return stmt |
| 380 | } |
| 381 | |
| 382 | func (c *cc) convertDropTableStmt(n *pcast.DropTableStmt) ast.Node { |
| 383 | drop := &ast.DropTableStmt{IfExists: n.IfExists} |
no test coverage detected