extractSetFieldNames extracts the target column names from an UPDATE SET clause.
(stmt *ast.UpdateStmt)
| 186 | |
| 187 | // extractSetFieldNames extracts the target column names from an UPDATE SET clause. |
| 188 | func extractSetFieldNames(stmt *ast.UpdateStmt) []string { |
| 189 | if stmt.TargetList == nil { |
| 190 | return nil |
| 191 | } |
| 192 | var fields []string |
| 193 | for _, item := range stmt.TargetList.Items { |
| 194 | rt, ok := item.(*ast.ResTarget) |
| 195 | if !ok || rt.Name == "" { |
| 196 | continue |
| 197 | } |
| 198 | // Take the last name component (the actual column name). |
| 199 | // For "SET test.c1 = 1", Name="test", Indirection=["c1"] → want "c1". |
| 200 | // For "SET c1 = 1", Name="c1", Indirection=nil → want "c1". |
| 201 | // For "SET schema.col[1] = val", Indirection=["col", integer] → want "col". |
| 202 | if rt.Indirection != nil && rt.Indirection.Len() > 0 { |
| 203 | found := false |
| 204 | for j := rt.Indirection.Len() - 1; j >= 0; j-- { |
| 205 | if s, ok := rt.Indirection.Items[j].(*ast.String); ok { |
| 206 | fields = append(fields, s.Str) |
| 207 | found = true |
| 208 | break |
| 209 | } |
| 210 | } |
| 211 | if found { |
| 212 | continue |
| 213 | } |
| 214 | } |
| 215 | fields = append(fields, rt.Name) |
| 216 | } |
| 217 | return fields |
| 218 | } |
| 219 | |
| 220 | func disjoint(a []string, b map[string]bool) bool { |
| 221 | for _, item := range a { |