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.
()
| 1394 | // Array types have the same type modifier as the contents of the array. |
| 1395 | // The value will be -1 for types that do not need atttypmod. |
| 1396 | func (t *T) TypeModifier() int32 { |
| 1397 | if t.Family() == ArrayFamily { |
| 1398 | return t.ArrayContents().TypeModifier() |
| 1399 | } |
| 1400 | // The type modifier for "char" is always -1. |
| 1401 | if t.Oid() == oid.T_char { |
| 1402 | return int32(-1) |
| 1403 | } |
| 1404 | |
| 1405 | switch t.Family() { |
| 1406 | case StringFamily, CollatedStringFamily: |
| 1407 | if width := t.Width(); width != 0 { |
| 1408 | // Postgres adds 4 to the attypmod for bounded string types, the |
| 1409 | // var header size. |
| 1410 | return width + 4 |
| 1411 | } |
| 1412 | case BitFamily, PGVectorFamily: |
| 1413 | if width := t.Width(); width != 0 { |
| 1414 | return width |
| 1415 | } |
| 1416 | case TimestampFamily, TimestampTZFamily, TimeFamily, TimeTZFamily, IntervalFamily: |
| 1417 | // For timestamp the precision is the type modifier value. |
| 1418 | if !t.InternalType.TimePrecisionIsSet { |
| 1419 | return -1 |
| 1420 | } |
| 1421 | return t.Precision() |
| 1422 | case DecimalFamily: |
| 1423 | // attTypMod is calculated by putting the precision in the upper |
| 1424 | // bits and the scale in the lower bits of a 32-bit int, and adding |
| 1425 | // 4 (the var header size). We mock this for clients' sake. See |
| 1426 | // https://github.com/postgres/postgres/blob/5a2832465fd8984d089e8c44c094e6900d987fcd/src/backend/utils/adt/numeric.c#L1242. |
| 1427 | if width, precision := t.Width(), t.Precision(); precision != 0 || width != 0 { |
| 1428 | return ((precision << 16) | width) + 4 |
| 1429 | } |
| 1430 | } |
| 1431 | return int32(-1) |
| 1432 | } |
| 1433 | |
| 1434 | // WithoutTypeModifiers returns a copy of the given type with the type modifiers |
| 1435 | // reset, if the type has modifiers. The returned type has arbitrary width and |
nothing calls this directly
no test coverage detected