Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 3076 | |
| 3077 | // Format implements the NodeFormatter interface. |
| 3078 | func (d *DTuple) Format(ctx *FmtCtx) { |
| 3079 | if ctx.HasFlags(fmtPgwireFormat) { |
| 3080 | d.pgwireFormat(ctx) |
| 3081 | return |
| 3082 | } |
| 3083 | |
| 3084 | typ := d.ResolvedType() |
| 3085 | showLabels := len(typ.TupleLabels()) > 0 |
| 3086 | if showLabels { |
| 3087 | ctx.WriteByte('(') |
| 3088 | } |
| 3089 | ctx.WriteByte('(') |
| 3090 | comma := "" |
| 3091 | parsable := ctx.HasFlags(FmtParsable) |
| 3092 | for i, v := range d.D { |
| 3093 | ctx.WriteString(comma) |
| 3094 | ctx.FormatNode(v) |
| 3095 | if parsable && (v == DNull) && len(typ.TupleContents()) > i { |
| 3096 | // If Tuple has types.Unknown for this slot, then we can't determine |
| 3097 | // the column type to write this annotation. Somebody else will provide |
| 3098 | // an error message in this case, if necessary, so just skip the |
| 3099 | // annotation and continue. |
| 3100 | if typ.TupleContents()[i].Family() != types.UnknownFamily { |
| 3101 | ctx.WriteString("::") |
| 3102 | ctx.WriteString(typ.TupleContents()[i].SQLString()) |
| 3103 | } |
| 3104 | } |
| 3105 | comma = ", " |
| 3106 | } |
| 3107 | if len(d.D) == 1 { |
| 3108 | // Ensure the pretty-printed 1-value tuple is not ambiguous with |
| 3109 | // the equivalent value enclosed in grouping parentheses. |
| 3110 | ctx.WriteByte(',') |
| 3111 | } |
| 3112 | ctx.WriteByte(')') |
| 3113 | if showLabels { |
| 3114 | ctx.WriteString(" AS ") |
| 3115 | comma := "" |
| 3116 | for i := range typ.TupleLabels() { |
| 3117 | ctx.WriteString(comma) |
| 3118 | ctx.FormatNode((*Name)(&typ.TupleLabels()[i])) |
| 3119 | comma = ", " |
| 3120 | } |
| 3121 | ctx.WriteByte(')') |
| 3122 | } |
| 3123 | } |
| 3124 | |
| 3125 | // Sorted returns true if the tuple is known to be sorted (and contains no |
| 3126 | // NULLs). |
nothing calls this directly
no test coverage detected