Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 1479 | |
| 1480 | // Format implements the NodeFormatter interface. |
| 1481 | func (d *DTuple) Format(ctx *FmtCtx) { |
| 1482 | if ctx.HasFlags(fmtPgwireFormat) { |
| 1483 | d.pgwireFormat(ctx) |
| 1484 | return |
| 1485 | } |
| 1486 | |
| 1487 | typ := d.ResolvedType() |
| 1488 | showLabels := len(typ.TupleLabels()) > 0 |
| 1489 | if showLabels { |
| 1490 | ctx.WriteByte('(') |
| 1491 | } |
| 1492 | ctx.WriteByte('(') |
| 1493 | comma := "" |
| 1494 | parsable := ctx.HasFlags(FmtParsable) |
| 1495 | for i, v := range d.D { |
| 1496 | ctx.WriteString(comma) |
| 1497 | ctx.FormatNode(v) |
| 1498 | if parsable && (v == DNull) && len(typ.TupleContents()) > i { |
| 1499 | // If Tuple has types.Unknown for this slot, then we can't determine |
| 1500 | // the column type to write this annotation. Somebody else will provide |
| 1501 | // an error message in this case, if necessary, so just skip the |
| 1502 | // annotation and continue. |
| 1503 | if typ.TupleContents()[i].Family() != types.UnknownFamily { |
| 1504 | ctx.WriteString("::") |
| 1505 | ctx.WriteString(typ.TupleContents()[i].SQLString()) |
| 1506 | } |
| 1507 | } |
| 1508 | comma = ", " |
| 1509 | } |
| 1510 | if len(d.D) == 1 { |
| 1511 | // Ensure the pretty-printed 1-value tuple is not ambiguous with |
| 1512 | // the equivalent value enclosed in grouping parentheses. |
| 1513 | ctx.WriteByte(',') |
| 1514 | } |
| 1515 | ctx.WriteByte(')') |
| 1516 | if showLabels { |
| 1517 | ctx.WriteString(" AS ") |
| 1518 | comma := "" |
| 1519 | for i := range typ.TupleLabels() { |
| 1520 | ctx.WriteString(comma) |
| 1521 | ctx.FormatNode((*Name)(&typ.TupleLabels()[i])) |
| 1522 | comma = ", " |
| 1523 | } |
| 1524 | ctx.WriteByte(')') |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | // Sorted returns true if the tuple is known to be sorted (and contains no |
| 1529 | // NULLs). |
nothing calls this directly
no test coverage detected