Also keep in mind that the system doesn't always retain the typmod. So the datum should be possible to interpret without the typmod. Incidental effects such as length limits or precision displayed are ok but the meaning shouldn't be changed.
Alvaro Herrera <alvherre@2ndquadrant.com> writes: > Bruce Momjian escribió: >> Well, typmods are type-specific, so there is no official way to >> calculate it. I would look at how an existing type uses typmod and copy >> that.
One other point is that if you do consult the varchar functions as an example, be aware that there's an offset of 4 in their definition of the typmod (eg, for varchar(3) the stored typmod is 7). This is entirely for legacy reasons so there's no good reason to duplicate it in a new custom-made type. Except for the rule that negative values mean "unspecified typmod" (which you have to support), you can define the contents of the typmod value however you want.