stringTypeSQL returns the visible type name plus any width specifier for the STRING/COLLATEDSTRING type.
()
| 2453 | // stringTypeSQL returns the visible type name plus any width specifier for the |
| 2454 | // STRING/COLLATEDSTRING type. |
| 2455 | func (t *T) stringTypeSQL() string { |
| 2456 | typName := "STRING" |
| 2457 | switch t.Oid() { |
| 2458 | case oid.T_text: |
| 2459 | typName = "TEXT" |
| 2460 | case oid.T_varchar: |
| 2461 | typName = "VARCHAR" |
| 2462 | case oid.T_bpchar: |
| 2463 | typName = "CHAR" |
| 2464 | case oid.T_char: |
| 2465 | // Yes, that's the name. The ways of PostgreSQL are inscrutable. |
| 2466 | typName = `"char"` |
| 2467 | case oid.T_name: |
| 2468 | typName = "NAME" |
| 2469 | } |
| 2470 | |
| 2471 | // In general, if there is a specified width we want to print it next to the |
| 2472 | // type. However, in the specific case of CHAR and "char", the default is 1 |
| 2473 | // and the width should be omitted in that case. |
| 2474 | if t.Width() > 0 { |
| 2475 | o := t.Oid() |
| 2476 | if t.Width() != 1 || (o != oid.T_bpchar && o != oid.T_char) { |
| 2477 | typName = fmt.Sprintf("%s(%d)", typName, t.Width()) |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | return typName |
| 2482 | } |
| 2483 | |
| 2484 | // IsHydrated returns true if this is a user-defined type and the TypeMeta |
| 2485 | // is hydrated. |
no test coverage detected