String returns the name of the type, similar to the Name method. However, it expands CollatedStringFamily, ArrayFamily, and TupleFamily types to be more descriptive. TODO(andyk): It'd be nice to have this return SqlString() method output, since that is more descriptive.
()
| 2764 | // TODO(andyk): It'd be nice to have this return SqlString() method output, |
| 2765 | // since that is more descriptive. |
| 2766 | func (t *T) String() string { |
| 2767 | switch t.Family() { |
| 2768 | case CollatedStringFamily: |
| 2769 | if t.Locale() == "" { |
| 2770 | // Used in telemetry. |
| 2771 | return fmt.Sprintf("collated%s{*}", t.Name()) |
| 2772 | } |
| 2773 | return fmt.Sprintf("collated%s{%s}", t.Name(), t.Locale()) |
| 2774 | |
| 2775 | case ArrayFamily: |
| 2776 | switch t.Oid() { |
| 2777 | case oid.T_oidvector, oid.T_int2vector: |
| 2778 | return t.Name() |
| 2779 | } |
| 2780 | return t.ArrayContents().String() + "[]" |
| 2781 | |
| 2782 | case TupleFamily: |
| 2783 | var buf bytes.Buffer |
| 2784 | buf.WriteString("tuple") |
| 2785 | if len(t.TupleContents()) != 0 && !IsWildcardTupleType(t) { |
| 2786 | buf.WriteByte('{') |
| 2787 | for i, typ := range t.TupleContents() { |
| 2788 | if i != 0 { |
| 2789 | buf.WriteString(", ") |
| 2790 | } |
| 2791 | buf.WriteString(typ.String()) |
| 2792 | if t.TupleLabels() != nil { |
| 2793 | buf.WriteString(" AS ") |
| 2794 | buf.WriteString(t.InternalType.TupleLabels[i]) |
| 2795 | } |
| 2796 | } |
| 2797 | buf.WriteByte('}') |
| 2798 | } |
| 2799 | return buf.String() |
| 2800 | case IntervalFamily, TimestampFamily, TimestampTZFamily, TimeFamily, TimeTZFamily: |
| 2801 | if t.InternalType.Precision > 0 || t.InternalType.TimePrecisionIsSet { |
| 2802 | return fmt.Sprintf("%s(%d)", t.Name(), t.Precision()) |
| 2803 | } |
| 2804 | } |
| 2805 | return t.Name() |
| 2806 | } |
| 2807 | |
| 2808 | // MarshalText is implemented here so that gogo/protobuf know how to text marshal |
| 2809 | // protobuf struct directly/indirectly depends on types.T without panic. |
nothing calls this directly
no test coverage detected