returningRefsColumn reports whether a RETURNING item references, by name, any column in cols. RETURNING * is deliberately NOT treated as a hit: it is the common row-identification idiom (callers typically consume only the key), and rejecting it would break legitimate upsert patterns. The narrower ri
(ret *pg_query.Node, cols map[string]bool)
| 428 | // caller reads a modified column out of a RETURNING * is left as a documented |
| 429 | // limitation. |
| 430 | func returningRefsColumn(ret *pg_query.Node, cols map[string]bool) bool { |
| 431 | found := false |
| 432 | WalkFunc(&pg_query.ParseResult{Stmts: []*pg_query.RawStmt{{Stmt: ret}}}, func(n *pg_query.Node) bool { |
| 433 | if cr := n.GetColumnRef(); cr != nil { |
| 434 | for _, f := range cr.Fields { |
| 435 | if s := f.GetString_(); s != nil && cols[strings.ToLower(s.Sval)] { |
| 436 | found = true |
| 437 | return false |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | return true |
| 442 | }) |
| 443 | return found |
| 444 | } |
| 445 | |
| 446 | // updateToSelect converts UPDATE...FROM...WHERE...RETURNING to equivalent SELECT |
| 447 | func (t *WritableCTETransform) updateToSelect( |
no test coverage detected