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

Method SQLStandardNameWithTypmod

pkg/sql/types/types.go:1137–1295  ·  view source on GitHub ↗

var telemetryNameReplaceRegex = regexp.MustCompile("[^a-zA-Z0-9]") TelemetryName returns a name that is friendly for telemetry. func (t *T) TelemetryName() string { return strings.ToLower(telemetryNameReplaceRegex.ReplaceAllString(t.SQLString(), "_")) } SQLStandardNameWithTypmod is like SQLStandard

(haveTypmod bool, typmod int)

Source from the content-addressed store, hash-verified

1135// This function is full of special cases. See backend/utils/adt/format_type.c
1136// in Postgres.
1137func (t *T) SQLStandardNameWithTypmod(haveTypmod bool, typmod int) string {
1138 var buf strings.Builder
1139 switch t.Family() {
1140 case AnyFamily:
1141 return "anyelement"
1142 case ArrayFamily:
1143 switch t.Oid() {
1144 case oid.T_oidvector:
1145 return "oidvector"
1146 case oid.T_int2vector:
1147 return "int2vector"
1148 }
1149 return t.ArrayContents().SQLStandardName() + "[]"
1150 case BitFamily:
1151 if t.Oid() == oid.T_varbit {
1152 buf.WriteString("bit varying")
1153 } else {
1154 buf.WriteString("bit")
1155 }
1156 if !haveTypmod || typmod <= 0 {
1157 return buf.String()
1158 }
1159 buf.WriteString(fmt.Sprintf("(%d)", typmod))
1160 return buf.String()
1161 case BoolFamily:
1162 return "boolean"
1163 case BytesFamily:
1164 return "bytea"
1165 case DateFamily:
1166 return "date"
1167 case DecimalFamily:
1168 if !haveTypmod || typmod <= 0 {
1169 return "numeric"
1170 }
1171 // The typmod of a numeric has the precision in the upper bits and the
1172 // scale in the lower bits of a 32-bit int, after subtracting 4 (the var
1173 // header size). See numeric.c.
1174 typmod -= 4
1175 return fmt.Sprintf(
1176 "numeric(%d,%d)",
1177 (typmod>>16)&0xffff,
1178 typmod&0xffff,
1179 )
1180
1181 case FloatFamily:
1182 switch t.Width() {
1183 case 32:
1184 return "real"
1185 case 64:
1186 return "double precision"
1187 default:
1188 panic(errors.AssertionFailedf("programming error: unknown float width: %d", t.Width()))
1189 }
1190 case INetFamily:
1191 return "inet"
1192 case IntFamily:
1193 switch t.Width() {
1194 case 16:

Callers 1

SQLStandardNameMethod · 0.95

Calls 6

FamilyMethod · 0.95
OidMethod · 0.95
ArrayContentsMethod · 0.95
WidthMethod · 0.95
SQLStandardNameMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected