MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / stringTypeSQL

Method stringTypeSQL

pkg/sql/types/types.go:2044–2069  ·  view source on GitHub ↗

stringTypeSQL returns the visible type name plus any width specifier for the STRING/COLLATEDSTRING type.

()

Source from the content-addressed store, hash-verified

2042// stringTypeSQL returns the visible type name plus any width specifier for the
2043// STRING/COLLATEDSTRING type.
2044func (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
2071var typNameLiterals map[string]*T
2072

Callers 2

SQLStringMethod · 0.95
collatedStringTypeSQLMethod · 0.95

Calls 2

OidMethod · 0.95
WidthMethod · 0.95

Tested by

no test coverage detected