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). The value will be -1 for types that do not need atttypmod.
()
| 940 | // at table creation time (for example, the maximum length of a varchar column). |
| 941 | // The value will be -1 for types that do not need atttypmod. |
| 942 | func (t *T) TypeModifier() int32 { |
| 943 | typeModifier := int32(-1) |
| 944 | if width := t.Width(); width != 0 { |
| 945 | switch t.Family() { |
| 946 | case StringFamily: |
| 947 | // Postgres adds 4 to the attypmod for bounded string types, the |
| 948 | // var header size. |
| 949 | typeModifier = width + 4 |
| 950 | case BitFamily: |
| 951 | typeModifier = width |
| 952 | case DecimalFamily: |
| 953 | // attTypMod is calculated by putting the precision in the upper |
| 954 | // bits and the scale in the lower bits of a 32-bit int, and adding |
| 955 | // 4 (the var header size). We mock this for clients' sake. See |
| 956 | // numeric.c. |
| 957 | typeModifier = ((t.Precision() << 16) | width) + 4 |
| 958 | } |
| 959 | } |
| 960 | return typeModifier |
| 961 | } |
| 962 | |
| 963 | // Scale is an alias method for Width, used for clarity for types in |
| 964 | // DecimalFamily. |