1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.152 2004/12/23 05:37:39 tgl Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.153 2005/01/08 05:19:18 tgl Exp $
3
3
-->
4
4
5
5
<chapter id="datatype">
@@ -446,9 +446,9 @@ $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.152 2004/12/23 05:37:39 tgl Ex
446
446
The type <type>numeric</type> can store numbers with up to 1000
447
447
digits of precision and perform calculations exactly. It is
448
448
especially recommended for storing monetary amounts and other
449
- quantities where exactness is required. However, the
450
- <type>numeric</type> type is very slow compared to the
451
- floating-point types described in the next section.
449
+ quantities where exactness is required. However, arithmetic on
450
+ <type>numeric</type> values is very slow compared to the integer
451
+ types, or to the floating-point types described in the next section.
452
452
</para>
453
453
454
454
<para>
@@ -464,7 +464,8 @@ $PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.152 2004/12/23 05:37:39 tgl Ex
464
464
</para>
465
465
466
466
<para>
467
- Both the precision and the scale of the numeric type can be
467
+ Both the maximum precision and the maximum scale of a
468
+ <type>numeric</type> column can be
468
469
configured. To declare a column of type <type>numeric</type> use
469
470
the syntax
470
471
<programlisting>
@@ -492,10 +493,19 @@ NUMERIC
492
493
</para>
493
494
494
495
<para>
495
- If the precision or scale of a value is greater than the declared
496
- precision or scale of a column, the system will attempt to round
497
- the value. If the value cannot be rounded so as to satisfy the
498
- declared limits, an error is raised.
496
+ If the scale of a value to be stored is greater than the declared
497
+ scale of the column, the system will round the value to the specified
498
+ number of fractional digits. Then, if the number of digits to the
499
+ left of the decimal point exceeds the declared precision minus the
500
+ declared scale, an error is raised.
501
+ </para>
502
+
503
+ <para>
504
+ Numeric values are physically stored without any extra leading or
505
+ trailing zeroes. Thus, the declared precision and scale of a column
506
+ are maximums, not fixed allocations. (In this sense the <type>numeric</>
507
+ type is more akin to <type>varchar(<replaceable>n</>)</type>
508
+ than to <type>char(<replaceable>n</>)</type>.)
499
509
</para>
500
510
501
511
<para>
@@ -1089,13 +1099,18 @@ SELECT b, char_length(b) FROM test2;
1089
1099
1090
1100
<para>
1091
1101
A binary string is a sequence of octets (or bytes). Binary
1092
- strings are distinguished from characters strings by two
1102
+ strings are distinguished from character strings by two
1093
1103
characteristics: First, binary strings specifically allow storing
1094
1104
octets of value zero and other <quote>non-printable</quote>
1095
- octets (defined as octets outside the range 32 to 126).
1105
+ octets (usually, octets outside the range 32 to 126).
1106
+ Character strings disallow zero octets, and also disallow any
1107
+ other octet values and sequences of octet values that are invalid
1108
+ according to the database's selected character set encoding.
1096
1109
Second, operations on binary strings process the actual bytes,
1097
- whereas the encoding and processing of character strings depends
1098
- on locale settings.
1110
+ whereas the processing of character strings depends on locale settings.
1111
+ In short, binary strings are appropriate for storing data that the
1112
+ programmer thinks of as <quote>raw bytes</>, whereas character
1113
+ strings are appropriate for storing text.
1099
1114
</para>
1100
1115
1101
1116
<para>
@@ -1254,7 +1269,7 @@ SELECT b, char_length(b) FROM test2;
1254
1269
<para>
1255
1270
The <acronym>SQL</acronym> standard defines a different binary
1256
1271
string type, called <type>BLOB</type> or <type>BINARY LARGE
1257
- OBJECT</type>. The input format is different compared to
1272
+ OBJECT</type>. The input format is different from
1258
1273
<type>bytea</type>, but the provided functions and operators are
1259
1274
mostly the same.
1260
1275
</para>
@@ -1295,7 +1310,9 @@ SELECT b, char_length(b) FROM test2;
1295
1310
<para>
1296
1311
<productname>PostgreSQL</productname> supports the full set of
1297
1312
<acronym>SQL</acronym> date and time types, shown in <xref
1298
- linkend="datatype-datetime-table">.
1313
+ linkend="datatype-datetime-table">. The operations available
1314
+ on these data types are described in
1315
+ <xref linkend="functions-datetime">.
1299
1316
</para>
1300
1317
1301
1318
<table id="datatype-datetime-table">
@@ -1842,8 +1859,10 @@ January 8 04:05:06 1999 PST
1842
1859
are specially represented inside the system and will be displayed
1843
1860
the same way; but the others are simply notational shorthands
1844
1861
that will be converted to ordinary date/time values when read.
1845
- All of these values are treated as normal constants and need to be
1846
- written in single quotes.
1862
+ (In particular, <literal>now</> and related strings are converted
1863
+ to a specific time value as soon as they are read.)
1864
+ All of these values need to be written in single quotes when used
1865
+ as constants in SQL commands.
1847
1866
</para>
1848
1867
1849
1868
<table id="datatype-datetime-special-table">
@@ -1908,7 +1927,7 @@ January 8 04:05:06 1999 PST
1908
1927
<literal>CURRENT_DATE</literal>, <literal>CURRENT_TIME</literal>,
1909
1928
<literal>CURRENT_TIMESTAMP</literal>, <literal>LOCALTIME</literal>,
1910
1929
<literal>LOCALTIMESTAMP</literal>. The latter four accept an
1911
- optional precision specification. (See also <xref
1930
+ optional precision specification. (See <xref
1912
1931
linkend="functions-datetime-current">.) Note however that these are
1913
1932
SQL functions and are <emphasis>not</> recognized as data input strings.
1914
1933
</para>
@@ -2265,7 +2284,7 @@ SELECT * FROM test1 WHERE a;
2265
2284
not work). This can be accomplished using the
2266
2285
<literal>CASE</literal> expression: <literal>CASE WHEN
2267
2286
<replaceable>boolval</replaceable> THEN 'value if true' ELSE
2268
- 'value if false' END</literal>. See also <xref
2287
+ 'value if false' END</literal>. See <xref
2269
2288
linkend="functions-conditional">.
2270
2289
</para>
2271
2290
</tip>
@@ -2454,9 +2473,9 @@ SELECT * FROM test1 WHERE a;
2454
2473
<para>
2455
2474
Paths are represented by lists of connected points. Paths can be
2456
2475
<firstterm>open</firstterm>, where
2457
- the first and last points in the list are not connected, or
2476
+ the first and last points in the list are not considered connected, or
2458
2477
<firstterm>closed</firstterm>,
2459
- where the first and last points are connected.
2478
+ where the first and last points are considered connected.
2460
2479
</para>
2461
2480
2462
2481
<para>
@@ -2558,7 +2577,7 @@ SELECT * FROM test1 WHERE a;
2558
2577
is preferable to use these types instead of plain text types to store
2559
2578
network addresses, because
2560
2579
these types offer input error checking and several specialized
2561
- operators and functions.
2580
+ operators and functions (see <xref linkend="functions-net">) .
2562
2581
</para>
2563
2582
2564
2583
<table tocentry="1" id="datatype-net-types-table">
@@ -3006,12 +3025,25 @@ SELECT * FROM test;
3006
3025
for specialized input and output routines. These routines are able
3007
3026
to accept and display symbolic names for system objects, rather than
3008
3027
the raw numeric value that type <type>oid</> would use. The alias
3009
- types allow simplified lookup of OID values for objects: for example,
3010
- one may write <literal>'mytable'::regclass</> to get the OID of table
3011
- <literal>mytable</>, rather than <literal>SELECT oid FROM pg_class WHERE
3012
- relname = 'mytable'</>. (In reality, a much more complicated <command>SELECT</> would
3013
- be needed to deal with selecting the right OID when there are multiple
3014
- tables named <literal>mytable</> in different schemas.)
3028
+ types allow simplified lookup of OID values for objects. For example,
3029
+ to examine the <structname>pg_attribute</> rows related to a table
3030
+ <literal>mytable</>, one could write
3031
+ <programlisting>
3032
+ SELECT * FROM pg_attribute WHERE attrelid = 'mytable'::regclass;
3033
+ </programlisting>
3034
+ rather than
3035
+ <programlisting>
3036
+ SELECT * FROM pg_attribute
3037
+ WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'mytable');
3038
+ </programlisting>
3039
+ While that doesn't look all that bad by itself, it's still oversimplified.
3040
+ A far more complicated sub-select would be needed to
3041
+ select the right OID if there are multiple tables named
3042
+ <literal>mytable</> in different schemas.
3043
+ The <type>regclass</> input converter handles the table lookup according
3044
+ to the schema path setting, and so it does the <quote>right thing</>
3045
+ automatically. Similarly, casting a table's OID to
3046
+ <type>regclass</> is handy for symbolic display of a numeric OID.
3015
3047
</para>
3016
3048
3017
3049
<table id="datatype-oid-table">
0 commit comments