Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> For the text types I think it's generally length+4. For numeric, I think
> it's precision*65536+scale. The best way to find out is probably to
> declare a column of the target type and check.
Or experiment with format_type(), or read the source code for same.
For example:
regression=# select oid from pg_type where typname = 'numeric';
oid
------
1700
(1 row)
regression=# select format_type(1700, 10 * 65536 + 7);
format_type
---------------
numeric(10,3)
(1 row)
Looks like there's an offset of 4 for numeric, too. But a look into
src/backend/utils/adt/format_type.c gives the exact recipe ...
regards, tom lane