1- <!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.194 2007/04/05 01:46:27 momjian Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.195 2007/04/06 19:22:38 tgl Exp $ -->
22
33 <chapter id="datatype">
44 <title id="datatype-title">Data Types</title>
@@ -516,7 +516,7 @@ NUMERIC
516516 type is more akin to <type>varchar(<replaceable>n</>)</type>
517517 than to <type>char(<replaceable>n</>)</type>.) The actual storage
518518 requirement is two bytes for each group of four decimal digits,
519- plus eight bytes overhead.
519+ plusfive to eight bytes overhead.
520520 </para>
521521
522522 <indexterm>
@@ -842,9 +842,9 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab
842842 <tbody>
843843 <row>
844844 <entry>money</entry>
845- <entry>4 bytes</entry>
845+ <entry>8 bytes</entry>
846846 <entry>currency amount</entry>
847- <entry>-21474836.48 to +21474836.47 </entry>
847+ <entry>-92233720368547758.08 to +92233720368547758.07 </entry>
848848 </row>
849849 </tbody>
850850 </tgroup>
@@ -975,12 +975,13 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab
975975 </para>
976976
977977 <para>
978- The storage requirement for data of these types is 4 bytes plus the
979- actual string, and in case of <type>character</type> plus the
980- padding. Long strings are compressed by the system automatically, so
981- the physical requirement on disk might be less. Long values are also
982- stored in background tables so they do not interfere with rapid
983- access to the shorter column values. In any case, the longest
978+ The storage requirement for a short string (up to 126 bytes) is 1 byte
979+ plus the actual string, which includes the space padding in the case of
980+ <type>character</type>. Longer strings have 4 bytes overhead instead
981+ of 1. Long strings are compressed by the system automatically, so
982+ the physical requirement on disk might be less. Very long values are also
983+ stored in background tables so that they do not interfere with rapid
984+ access to shorter column values. In any case, the longest
984985 possible character string that can be stored is about 1 GB. (The
985986 maximum value that will be allowed for <replaceable>n</> in the data
986987 type declaration is less than that. It wouldn't be very useful to
@@ -994,8 +995,10 @@ ALTER SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceab
994995 <tip>
995996 <para>
996997 There are no performance differences between these three types,
997- apart from the increased storage size when using the blank-padded
998- type. While <type>character(<replaceable>n</>)</type> has performance
998+ apart from increased storage size when using the blank-padded
999+ type, and a few extra cycles to check the length when storing into
1000+ a length-constrained column. While
1001+ <type>character(<replaceable>n</>)</type> has performance
9991002 advantages in some other database systems, it has no such advantages in
10001003 <productname>PostgreSQL</productname>. In most situations
10011004 <type>text</type> or <type>character varying</type> should be used
@@ -1080,7 +1083,7 @@ SELECT b, char_length(b) FROM test2;
10801083 <row>
10811084 <entry><type>"char"</type></entry>
10821085 <entry>1 byte</entry>
1083- <entry>single-character internal type</entry>
1086+ <entry>single-byte internal type</entry>
10841087 </row>
10851088 <row>
10861089 <entry><type>name</type></entry>
@@ -1122,7 +1125,7 @@ SELECT b, char_length(b) FROM test2;
11221125 <tbody>
11231126 <row>
11241127 <entry><type>bytea</type></entry>
1125- <entry>4 bytes plus the actual binary string</entry>
1128+ <entry>1 or 4 bytes plus the actual binary string</entry>
11261129 <entry>variable-length binary string</entry>
11271130 </row>
11281131 </tbody>
@@ -2879,13 +2882,13 @@ SELECT person.name, holidays.num_weeks FROM person, holidays
28792882
28802883 <row>
28812884 <entry><type>cidr</type></entry>
2882- <entry>12 or24 bytes</entry>
2885+ <entry>7 or19 bytes</entry>
28832886 <entry>IPv4 and IPv6 networks</entry>
28842887 </row>
28852888
28862889 <row>
28872890 <entry><type>inet</type></entry>
2888- <entry>12 or24 bytes</entry>
2891+ <entry>7 or19 bytes</entry>
28892892 <entry>IPv4 and IPv6 hosts and networks</entry>
28902893 </row>
28912894
@@ -3188,6 +3191,12 @@ SELECT * FROM test;
31883191</programlisting>
31893192 </example>
31903193
3194+ <para>
3195+ A bit string value requires 1 byte for each group of 8 bits, plus
3196+ 5 or 8 bytes overhead depending on the length of the string
3197+ (but long values may be compressed or moved out-of-line, as explained
3198+ in <xref linkend="datatype-character"> for character strings).
3199+ </para>
31913200 </sect1>
31923201
31933202 <sect1 id="datatype-xml">