onConflictSQL renders an ON CONFLICT clause.
(oc *ast.OnConflict)
| 1420 | |
| 1421 | // onConflictSQL renders an ON CONFLICT clause. |
| 1422 | func onConflictSQL(oc *ast.OnConflict) string { |
| 1423 | var sb strings.Builder |
| 1424 | sb.WriteString(" ON CONFLICT") |
| 1425 | if len(oc.Target) > 0 { |
| 1426 | sb.WriteString(" (") |
| 1427 | sb.WriteString(exprListSQL(oc.Target)) |
| 1428 | sb.WriteString(")") |
| 1429 | } |
| 1430 | if oc.Constraint != "" { |
| 1431 | sb.WriteString(" ON CONSTRAINT ") |
| 1432 | sb.WriteString(oc.Constraint) |
| 1433 | } |
| 1434 | if oc.Action.DoNothing { |
| 1435 | sb.WriteString(" DO NOTHING") |
| 1436 | } else if len(oc.Action.DoUpdate) > 0 { |
| 1437 | sb.WriteString(" DO UPDATE SET ") |
| 1438 | upds := make([]string, len(oc.Action.DoUpdate)) |
| 1439 | for i, u := range oc.Action.DoUpdate { |
| 1440 | upds[i] = exprSQL(u.Column) + " = " + exprSQL(u.Value) |
| 1441 | } |
| 1442 | sb.WriteString(strings.Join(upds, ", ")) |
| 1443 | if oc.Action.Where != nil { |
| 1444 | sb.WriteString(" WHERE ") |
| 1445 | sb.WriteString(exprSQL(oc.Action.Where)) |
| 1446 | } |
| 1447 | } |
| 1448 | return sb.String() |
| 1449 | } |
| 1450 | |
| 1451 | // columnDefSQL renders a column definition. |
| 1452 | func columnDefSQL(c *ast.ColumnDef) string { |
no test coverage detected