stringTypeSQL returns the visible type name plus any width specifier for the STRING/COLLATEDSTRING type.
()
| 2042 | // stringTypeSQL returns the visible type name plus any width specifier for the |
| 2043 | // STRING/COLLATEDSTRING type. |
| 2044 | func (t *T) stringTypeSQL() string { |
| 2045 | typName := "STRING" |
| 2046 | switch t.Oid() { |
| 2047 | case oid.T_varchar: |
| 2048 | typName = "VARCHAR" |
| 2049 | case oid.T_bpchar: |
| 2050 | typName = "CHAR" |
| 2051 | case oid.T_char: |
| 2052 | // Yes, that's the name. The ways of PostgreSQL are inscrutable. |
| 2053 | typName = `"char"` |
| 2054 | case oid.T_name: |
| 2055 | typName = "NAME" |
| 2056 | } |
| 2057 | |
| 2058 | // In general, if there is a specified width we want to print it next to the |
| 2059 | // type. However, in the specific case of CHAR and "char", the default is 1 |
| 2060 | // and the width should be omitted in that case. |
| 2061 | if t.Width() > 0 { |
| 2062 | o := t.Oid() |
| 2063 | if t.Width() != 1 || (o != oid.T_bpchar && o != oid.T_char) { |
| 2064 | typName = fmt.Sprintf("%s(%d)", typName, t.Width()) |
| 2065 | } |
| 2066 | } |
| 2067 | |
| 2068 | return typName |
| 2069 | } |
| 2070 | |
| 2071 | var typNameLiterals map[string]*T |
| 2072 |
no test coverage detected