Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 4723 | |
| 4724 | // Format implements the NodeFormatter interface. |
| 4725 | func (d *DTuple) Format(ctx *FmtCtx) { |
| 4726 | if ctx.HasFlags(fmtPgwireFormat) { |
| 4727 | d.pgwireFormat(ctx) |
| 4728 | return |
| 4729 | } |
| 4730 | |
| 4731 | typ := d.ResolvedType() |
| 4732 | tupleContents := typ.TupleContents() |
| 4733 | showLabels := len(typ.TupleLabels()) > 0 |
| 4734 | if showLabels { |
| 4735 | ctx.WriteByte('(') |
| 4736 | } |
| 4737 | ctx.WriteByte('(') |
| 4738 | comma := "" |
| 4739 | parsable := ctx.HasFlags(FmtParsable) |
| 4740 | for i, v := range d.D { |
| 4741 | ctx.WriteString(comma) |
| 4742 | ctx.FormatNode(v) |
| 4743 | if parsable && (v == DNull) && len(tupleContents) > i { |
| 4744 | // If Tuple has types.Unknown for this slot, then we can't determine |
| 4745 | // the column type to write this annotation. Somebody else will provide |
| 4746 | // an error message in this case, if necessary, so just skip the |
| 4747 | // annotation and continue. |
| 4748 | if tupleContents[i].Family() != types.UnknownFamily { |
| 4749 | nullType := tupleContents[i] |
| 4750 | if ctx.HasFlags(fmtDisambiguateDatumTypes) { |
| 4751 | ctx.WriteString(":::") |
| 4752 | ctx.FormatTypeReference(nullType) |
| 4753 | } else { |
| 4754 | ctx.WriteString("::") |
| 4755 | ctx.WriteString(nullType.SQLString()) |
| 4756 | } |
| 4757 | } |
| 4758 | } |
| 4759 | comma = ", " |
| 4760 | } |
| 4761 | if len(d.D) == 1 { |
| 4762 | // Ensure the pretty-printed 1-value tuple is not ambiguous with |
| 4763 | // the equivalent value enclosed in grouping parentheses. |
| 4764 | ctx.WriteByte(',') |
| 4765 | } |
| 4766 | ctx.WriteByte(')') |
| 4767 | if showLabels { |
| 4768 | ctx.WriteString(" AS ") |
| 4769 | comma := "" |
| 4770 | for i := range typ.TupleLabels() { |
| 4771 | ctx.WriteString(comma) |
| 4772 | ctx.FormatNode((*Name)(&typ.TupleLabels()[i])) |
| 4773 | comma = ", " |
| 4774 | } |
| 4775 | ctx.WriteByte(')') |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | // Sorted returns true if the tuple is known to be sorted (and contains no |
| 4780 | // NULLs). |
no test coverage detected