MCPcopy Create free account
hub / github.com/dolthub/doltgresql / TypeModifier

Method TypeModifier

postgres/parser/types/types.go:1164–1186  ·  view source on GitHub ↗

TypeModifier returns the type modifier of the type. This corresponds to the pg_attribute.atttypmod column. atttypmod records type-specific data supplied at table creation time (for example, the maximum length of a varchar column). Array types have the same type modifier as the contents of the array.

()

Source from the content-addressed store, hash-verified

1162// Array types have the same type modifier as the contents of the array.
1163// The value will be -1 for types that do not need atttypmod.
1164func (t *T) TypeModifier() int32 {
1165 typeModifier := int32(-1)
1166 if t.Family() == ArrayFamily {
1167 return t.ArrayContents().TypeModifier()
1168 }
1169 if width := t.Width(); width != 0 {
1170 switch t.Family() {
1171 case StringFamily:
1172 // Postgres adds 4 to the attypmod for bounded string types, the
1173 // var header size.
1174 typeModifier = width + 4
1175 case BitFamily:
1176 typeModifier = width
1177 case DecimalFamily:
1178 // attTypMod is calculated by putting the precision in the upper
1179 // bits and the scale in the lower bits of a 32-bit int, and adding
1180 // 4 (the var header size). We mock this for clients' sake. See
1181 // numeric.c.
1182 typeModifier = ((t.Precision() << 16) | width) + 4
1183 }
1184 }
1185 return typeModifier
1186}
1187
1188// Scale is an alias method for Width, used for clarity for types in
1189// DecimalFamily.

Callers

nothing calls this directly

Calls 4

FamilyMethod · 0.95
ArrayContentsMethod · 0.95
WidthMethod · 0.95
PrecisionMethod · 0.95

Tested by

no test coverage detected