stringTypeSQL returns the visible type name plus any width specifier for the STRING/COLLATEDSTRING type.
()
| 3025 | // stringTypeSQL returns the visible type name plus any width specifier for the |
| 3026 | // STRING/COLLATEDSTRING type. |
| 3027 | func (t *T) stringTypeSQL() string { |
| 3028 | typName := "STRING" |
| 3029 | switch t.Oid() { |
| 3030 | case oid.T_varchar: |
| 3031 | typName = "VARCHAR" |
| 3032 | case oid.T_bpchar: |
| 3033 | if t.Width() == 0 { |
| 3034 | return "BPCHAR" |
| 3035 | } |
| 3036 | typName = "CHAR" |
| 3037 | case oid.T_char: |
| 3038 | // Yes, that's the name. The ways of PostgreSQL are inscrutable. |
| 3039 | typName = `"char"` |
| 3040 | case oid.T_name: |
| 3041 | typName = "NAME" |
| 3042 | } |
| 3043 | |
| 3044 | // In general, if there is a specified width we want to print it next to the |
| 3045 | // type. However, in the specific case of CHAR and "char", the default is 1 |
| 3046 | // and the width should be omitted in that case. |
| 3047 | if t.Width() > 0 { |
| 3048 | o := t.Oid() |
| 3049 | if t.Width() != 1 || (o != oid.T_bpchar && o != oid.T_char) { |
| 3050 | typName = fmt.Sprintf("%s(%d)", typName, t.Width()) |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | return typName |
| 3055 | } |
| 3056 | |
| 3057 | // IsHydrated returns true if this is a user-defined type and the TypeMeta |
| 3058 | // is hydrated. |
no test coverage detected