~ubuntu-branches/ubuntu/trusty/postgresql-9.3/trusty-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Numeric Types</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.3.13 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Data Types"
HREF="datatype.html"><LINK
REL="PREVIOUS"
TITLE="Data Types"
HREF="datatype.html"><LINK
REL="NEXT"
TITLE="Monetary Types"
HREF="datatype-money.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2016-05-09T21:13:26"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.3.13 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Data Types"
HREF="datatype.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 8. Data Types</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Monetary Types"
HREF="datatype-money.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="DATATYPE-NUMERIC"
>8.1. Numeric Types</A
></H1
><P
>    Numeric types consist of two-, four-, and eight-byte integers,
    four- and eight-byte floating-point numbers, and selectable-precision
    decimals.  <A
HREF="datatype-numeric.html#DATATYPE-NUMERIC-TABLE"
>Table 8-2</A
> lists the
    available types.
   </P
><DIV
CLASS="TABLE"
><A
NAME="DATATYPE-NUMERIC-TABLE"
></A
><P
><B
>Table 8-2. Numeric Types</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><COL><THEAD
><TR
><TH
>Name</TH
><TH
>Storage Size</TH
><TH
>Description</TH
><TH
>Range</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="TYPE"
>smallint</TT
></TD
><TD
>2 bytes</TD
><TD
>small-range integer</TD
><TD
>-32768 to +32767</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>integer</TT
></TD
><TD
>4 bytes</TD
><TD
>typical choice for integer</TD
><TD
>-2147483648 to +2147483647</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
>8 bytes</TD
><TD
>large-range integer</TD
><TD
>-9223372036854775808 to +9223372036854775807</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>decimal</TT
></TD
><TD
>variable</TD
><TD
>user-specified precision, exact</TD
><TD
>up to 131072 digits before the decimal point; up to 16383 digits after the decimal point</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>numeric</TT
></TD
><TD
>variable</TD
><TD
>user-specified precision, exact</TD
><TD
>up to 131072 digits before the decimal point; up to 16383 digits after the decimal point</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>real</TT
></TD
><TD
>4 bytes</TD
><TD
>variable-precision, inexact</TD
><TD
>6 decimal digits precision</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>double precision</TT
></TD
><TD
>8 bytes</TD
><TD
>variable-precision, inexact</TD
><TD
>15 decimal digits precision</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>smallserial</TT
></TD
><TD
>2 bytes</TD
><TD
>small autoincrementing integer</TD
><TD
>1 to 32767</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>serial</TT
></TD
><TD
>4 bytes</TD
><TD
>autoincrementing integer</TD
><TD
>1 to 2147483647</TD
></TR
><TR
><TD
><TT
CLASS="TYPE"
>bigserial</TT
></TD
><TD
>8 bytes</TD
><TD
>large autoincrementing integer</TD
><TD
>1 to 9223372036854775807</TD
></TR
></TBODY
></TABLE
></DIV
><P
>    The syntax of constants for the numeric types is described in
    <A
HREF="sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS"
>Section 4.1.2</A
>.  The numeric types have a
    full set of corresponding arithmetic operators and
    functions. Refer to <A
HREF="functions.html"
>Chapter 9</A
> for more
    information.  The following sections describe the types in detail.
   </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-INT"
>8.1.1. Integer Types</A
></H2
><P
>     The types <TT
CLASS="TYPE"
>smallint</TT
>, <TT
CLASS="TYPE"
>integer</TT
>, and
     <TT
CLASS="TYPE"
>bigint</TT
> store whole numbers, that is, numbers without
     fractional components, of various ranges.  Attempts to store
     values outside of the allowed range will result in an error.
    </P
><P
>     The type <TT
CLASS="TYPE"
>integer</TT
> is the common choice, as it offers
     the best balance between range, storage size, and performance.
     The <TT
CLASS="TYPE"
>smallint</TT
> type is generally only used if disk
     space is at a premium.  The <TT
CLASS="TYPE"
>bigint</TT
> type is designed to be
     used when the range of the <TT
CLASS="TYPE"
>integer</TT
> type is insufficient.
    </P
><P
>     <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> only specifies the integer types
     <TT
CLASS="TYPE"
>integer</TT
> (or <TT
CLASS="TYPE"
>int</TT
>),
     <TT
CLASS="TYPE"
>smallint</TT
>, and <TT
CLASS="TYPE"
>bigint</TT
>.  The
     type names <TT
CLASS="TYPE"
>int2</TT
>, <TT
CLASS="TYPE"
>int4</TT
>, and
     <TT
CLASS="TYPE"
>int8</TT
> are extensions, which are also used by some
     other <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> database systems.
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-NUMERIC-DECIMAL"
>8.1.2. Arbitrary Precision Numbers</A
></H2
><P
>     The type <TT
CLASS="TYPE"
>numeric</TT
> can store numbers with a
     very large number of digits and perform calculations exactly. It is
     especially recommended for storing monetary amounts and other
     quantities where exactness is required. However, arithmetic on
     <TT
CLASS="TYPE"
>numeric</TT
> values is very slow compared to the integer
     types, or to the floating-point types described in the next section.
    </P
><P
>     We use the following terms below:  The
     <I
CLASS="FIRSTTERM"
>scale</I
> of a <TT
CLASS="TYPE"
>numeric</TT
> is the
     count of decimal digits in the fractional part, to the right of
     the decimal point.  The <I
CLASS="FIRSTTERM"
>precision</I
> of a
     <TT
CLASS="TYPE"
>numeric</TT
> is the total count of significant digits in
     the whole number, that is, the number of digits to both sides of
     the decimal point.  So the number 23.5141 has a precision of 6
     and a scale of 4.  Integers can be considered to have a scale of
     zero.
    </P
><P
>     Both the maximum precision and the maximum scale of a
     <TT
CLASS="TYPE"
>numeric</TT
> column can be
     configured.  To declare a column of type <TT
CLASS="TYPE"
>numeric</TT
> use
     the syntax:
</P><PRE
CLASS="PROGRAMLISTING"
>NUMERIC(<TT
CLASS="REPLACEABLE"
><I
>precision</I
></TT
>, <TT
CLASS="REPLACEABLE"
><I
>scale</I
></TT
>)</PRE
><P>
     The precision must be positive, the scale zero or positive.
     Alternatively:
</P><PRE
CLASS="PROGRAMLISTING"
>NUMERIC(<TT
CLASS="REPLACEABLE"
><I
>precision</I
></TT
>)</PRE
><P>
     selects a scale of 0.  Specifying:
</P><PRE
CLASS="PROGRAMLISTING"
>NUMERIC</PRE
><P>
     without any precision or scale creates a column in which numeric
     values of any precision and scale can be stored, up to the
     implementation limit on precision.  A column of this kind will
     not coerce input values to any particular scale, whereas
     <TT
CLASS="TYPE"
>numeric</TT
> columns with a declared scale will coerce
     input values to that scale.  (The <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> standard
     requires a default scale of 0, i.e., coercion to integer
     precision.  We find this a bit useless.  If you're concerned
     about portability, always specify the precision and scale
     explicitly.)
    </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>      The maximum allowed precision when explicitly specified in the
      type declaration is 1000; <TT
CLASS="TYPE"
>NUMERIC</TT
> without a specified
      precision is subject to the limits described in <A
HREF="datatype-numeric.html#DATATYPE-NUMERIC-TABLE"
>Table 8-2</A
>.
     </P
></BLOCKQUOTE
></DIV
><P
>     If the scale of a value to be stored is greater than the declared
     scale of the column, the system will round the value to the specified
     number of fractional digits.  Then, if the number of digits to the
     left of the decimal point exceeds the declared precision minus the
     declared scale, an error is raised.
    </P
><P
>     Numeric values are physically stored without any extra leading or
     trailing zeroes.  Thus, the declared precision and scale of a column
     are maximums, not fixed allocations.  (In this sense the <TT
CLASS="TYPE"
>numeric</TT
>
     type is more akin to <TT
CLASS="TYPE"
>varchar(<TT
CLASS="REPLACEABLE"
><I
>n</I
></TT
>)</TT
>
     than to <TT
CLASS="TYPE"
>char(<TT
CLASS="REPLACEABLE"
><I
>n</I
></TT
>)</TT
>.)  The actual storage
     requirement is two bytes for each group of four decimal digits,
     plus three to eight bytes overhead.
    </P
><P
>     In addition to ordinary numeric values, the <TT
CLASS="TYPE"
>numeric</TT
>
     type allows the special value <TT
CLASS="LITERAL"
>NaN</TT
>, meaning
     <SPAN
CLASS="QUOTE"
>"not-a-number"</SPAN
>.  Any operation on <TT
CLASS="LITERAL"
>NaN</TT
>
     yields another <TT
CLASS="LITERAL"
>NaN</TT
>.  When writing this value
     as a constant in an SQL command, you must put quotes around it,
     for example <TT
CLASS="LITERAL"
>UPDATE table SET x = 'NaN'</TT
>.  On input,
     the string <TT
CLASS="LITERAL"
>NaN</TT
> is recognized in a case-insensitive manner.
    </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>      In most implementations of the <SPAN
CLASS="QUOTE"
>"not-a-number"</SPAN
> concept,
      <TT
CLASS="LITERAL"
>NaN</TT
> is not considered equal to any other numeric
      value (including <TT
CLASS="LITERAL"
>NaN</TT
>).  In order to allow
      <TT
CLASS="TYPE"
>numeric</TT
> values to be sorted and used in tree-based
      indexes, <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> treats <TT
CLASS="LITERAL"
>NaN</TT
>
      values as equal, and greater than all non-<TT
CLASS="LITERAL"
>NaN</TT
>
      values.
     </P
></BLOCKQUOTE
></DIV
><P
>     The types <TT
CLASS="TYPE"
>decimal</TT
> and <TT
CLASS="TYPE"
>numeric</TT
> are
     equivalent.  Both types are part of the <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
>
     standard.
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-FLOAT"
>8.1.3. Floating-Point Types</A
></H2
><P
>     The data types <TT
CLASS="TYPE"
>real</TT
> and <TT
CLASS="TYPE"
>double
     precision</TT
> are inexact, variable-precision numeric types.
     In practice, these types are usually implementations of
     <ACRONYM
CLASS="ACRONYM"
>IEEE</ACRONYM
> Standard 754 for Binary Floating-Point
     Arithmetic (single and double precision, respectively), to the
     extent that the underlying processor, operating system, and
     compiler support it.
    </P
><P
>     Inexact means that some values cannot be converted exactly to the
     internal format and are stored as approximations, so that storing
     and retrieving a value might show slight discrepancies.
     Managing these errors and how they propagate through calculations
     is the subject of an entire branch of mathematics and computer
     science and will not be discussed here, except for the
     following points:
     <P
></P
></P><UL
><LI
><P
>        If you require exact storage and calculations (such as for
        monetary amounts), use the <TT
CLASS="TYPE"
>numeric</TT
> type instead.
       </P
></LI
><LI
><P
>        If you want to do complicated calculations with these types
        for anything important, especially if you rely on certain
        behavior in boundary cases (infinity, underflow), you should
        evaluate the implementation carefully.
       </P
></LI
><LI
><P
>        Comparing two floating-point values for equality might not
        always work as expected.
       </P
></LI
></UL
><P>
    </P
><P
>     On most platforms, the <TT
CLASS="TYPE"
>real</TT
> type has a range of at least
     1E-37 to 1E+37 with a precision of at least 6 decimal digits.  The
     <TT
CLASS="TYPE"
>double precision</TT
> type typically has a range of around
     1E-307 to 1E+308 with a precision of at least 15 digits.  Values that
     are too large or too small will cause an error.  Rounding might
     take place if the precision of an input number is too high.
     Numbers too close to zero that are not representable as distinct
     from zero will cause an underflow error.
    </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>      The <A
HREF="runtime-config-client.html#GUC-EXTRA-FLOAT-DIGITS"
>extra_float_digits</A
> setting controls the
      number of extra significant digits included when a floating point
      value is converted to text for output.  With the default value of
      <TT
CLASS="LITERAL"
>0</TT
>, the output is the same on every platform
      supported by PostgreSQL.  Increasing it will produce output that
      more accurately represents the stored value, but may be unportable.
     </P
></BLOCKQUOTE
></DIV
><P
>     In addition to ordinary numeric values, the floating-point types
     have several special values:
<P
CLASS="LITERALLAYOUT"
><TT
CLASS="LITERAL"
>Infinity</TT
><br>
<TT
CLASS="LITERAL"
>-Infinity</TT
><br>
<TT
CLASS="LITERAL"
>NaN</TT
></P
>
     These represent the IEEE 754 special values
     <SPAN
CLASS="QUOTE"
>"infinity"</SPAN
>, <SPAN
CLASS="QUOTE"
>"negative infinity"</SPAN
>, and
     <SPAN
CLASS="QUOTE"
>"not-a-number"</SPAN
>, respectively.  (On a machine whose
     floating-point arithmetic does not follow IEEE 754, these values
     will probably not work as expected.)  When writing these values
     as constants in an SQL command, you must put quotes around them,
     for example <TT
CLASS="LITERAL"
>UPDATE table SET x = 'Infinity'</TT
>.  On input,
     these strings are recognized in a case-insensitive manner.
    </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>      IEEE754 specifies that <TT
CLASS="LITERAL"
>NaN</TT
> should not compare equal
      to any other floating-point value (including <TT
CLASS="LITERAL"
>NaN</TT
>).
      In order to allow floating-point values to be sorted and used
      in tree-based indexes, <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> treats
      <TT
CLASS="LITERAL"
>NaN</TT
> values as equal, and greater than all
      non-<TT
CLASS="LITERAL"
>NaN</TT
> values.
     </P
></BLOCKQUOTE
></DIV
><P
>     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> also supports the SQL-standard
     notations <TT
CLASS="TYPE"
>float</TT
> and
     <TT
CLASS="TYPE"
>float(<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>)</TT
> for specifying
     inexact numeric types.  Here, <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
> specifies
     the minimum acceptable precision in <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>binary</I
></SPAN
> digits.
     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> accepts
     <TT
CLASS="TYPE"
>float(1)</TT
> to <TT
CLASS="TYPE"
>float(24)</TT
> as selecting the
     <TT
CLASS="TYPE"
>real</TT
> type, while
     <TT
CLASS="TYPE"
>float(25)</TT
> to <TT
CLASS="TYPE"
>float(53)</TT
> select
     <TT
CLASS="TYPE"
>double precision</TT
>.  Values of <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>
     outside the allowed range draw an error.
     <TT
CLASS="TYPE"
>float</TT
> with no precision specified is taken to mean
     <TT
CLASS="TYPE"
>double precision</TT
>.
    </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>      Prior to <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 7.4, the precision in
      <TT
CLASS="TYPE"
>float(<TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
>)</TT
> was taken to mean
      so many <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>decimal</I
></SPAN
> digits.  This has been corrected to match the SQL
      standard, which specifies that the precision is measured in binary
      digits.  The assumption that <TT
CLASS="TYPE"
>real</TT
> and
      <TT
CLASS="TYPE"
>double precision</TT
> have exactly 24 and 53 bits in the
      mantissa respectively is correct for IEEE-standard floating point
      implementations.  On non-IEEE platforms it might be off a little, but
      for simplicity the same ranges of <TT
CLASS="REPLACEABLE"
><I
>p</I
></TT
> are used
      on all platforms.
     </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DATATYPE-SERIAL"
>8.1.4. Serial Types</A
></H2
><P
>     The data types <TT
CLASS="TYPE"
>smallserial</TT
>, <TT
CLASS="TYPE"
>serial</TT
> and
     <TT
CLASS="TYPE"
>bigserial</TT
> are not true types, but merely
     a notational convenience for creating unique identifier columns
     (similar to the <TT
CLASS="LITERAL"
>AUTO_INCREMENT</TT
> property
     supported by some other databases). In the current
     implementation, specifying:

</P><PRE
CLASS="PROGRAMLISTING"
>CREATE TABLE <TT
CLASS="REPLACEABLE"
><I
>tablename</I
></TT
> (
    <TT
CLASS="REPLACEABLE"
><I
>colname</I
></TT
> SERIAL
);</PRE
><P>

     is equivalent to specifying:

</P><PRE
CLASS="PROGRAMLISTING"
>CREATE SEQUENCE <TT
CLASS="REPLACEABLE"
><I
>tablename</I
></TT
>_<TT
CLASS="REPLACEABLE"
><I
>colname</I
></TT
>_seq;
CREATE TABLE <TT
CLASS="REPLACEABLE"
><I
>tablename</I
></TT
> (
    <TT
CLASS="REPLACEABLE"
><I
>colname</I
></TT
> integer NOT NULL DEFAULT nextval('<TT
CLASS="REPLACEABLE"
><I
>tablename</I
></TT
>_<TT
CLASS="REPLACEABLE"
><I
>colname</I
></TT
>_seq')
);
ALTER SEQUENCE <TT
CLASS="REPLACEABLE"
><I
>tablename</I
></TT
>_<TT
CLASS="REPLACEABLE"
><I
>colname</I
></TT
>_seq OWNED BY <TT
CLASS="REPLACEABLE"
><I
>tablename</I
></TT
>.<TT
CLASS="REPLACEABLE"
><I
>colname</I
></TT
>;</PRE
><P>

     Thus, we have created an integer column and arranged for its default
     values to be assigned from a sequence generator.  A <TT
CLASS="LITERAL"
>NOT NULL</TT
>
     constraint is applied to ensure that a null value cannot be
     inserted.  (In most cases you would also want to attach a
     <TT
CLASS="LITERAL"
>UNIQUE</TT
> or <TT
CLASS="LITERAL"
>PRIMARY KEY</TT
> constraint to prevent
     duplicate values from being inserted by accident, but this is
     not automatic.)  Lastly, the sequence is marked as <SPAN
CLASS="QUOTE"
>"owned by"</SPAN
>
     the column, so that it will be dropped if the column or table is dropped.
    </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>        Because <TT
CLASS="TYPE"
>smallserial</TT
>, <TT
CLASS="TYPE"
>serial</TT
> and
        <TT
CLASS="TYPE"
>bigserial</TT
> are implemented using sequences, there may
        be "holes" or gaps in the sequence of values which appears in the
        column, even if no rows are ever deleted.  A value allocated
        from the sequence is still "used up" even if a row containing that
        value is never successfully inserted into the table column.  This
        may happen, for example, if the inserting transaction rolls back.
        See <TT
CLASS="LITERAL"
>nextval()</TT
> in <A
HREF="functions-sequence.html"
>Section 9.16</A
>
        for details.
      </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>      Prior to <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 7.3, <TT
CLASS="TYPE"
>serial</TT
>
      implied <TT
CLASS="LITERAL"
>UNIQUE</TT
>.  This is no longer automatic.  If
      you wish a serial column to have a unique constraint or be a
      primary key, it must now be specified, just like
      any other data type.
     </P
></BLOCKQUOTE
></DIV
><P
>     To insert the next value of the sequence into the <TT
CLASS="TYPE"
>serial</TT
>
     column, specify that the <TT
CLASS="TYPE"
>serial</TT
>
     column should be assigned its default value. This can be done
     either by excluding the column from the list of columns in
     the <TT
CLASS="COMMAND"
>INSERT</TT
> statement, or through the use of
     the <TT
CLASS="LITERAL"
>DEFAULT</TT
> key word.
    </P
><P
>     The type names <TT
CLASS="TYPE"
>serial</TT
> and <TT
CLASS="TYPE"
>serial4</TT
> are
     equivalent: both create <TT
CLASS="TYPE"
>integer</TT
> columns.  The type
     names <TT
CLASS="TYPE"
>bigserial</TT
> and <TT
CLASS="TYPE"
>serial8</TT
> work
     the same way, except that they create a <TT
CLASS="TYPE"
>bigint</TT
>
     column.  <TT
CLASS="TYPE"
>bigserial</TT
> should be used if you anticipate
     the use of more than 2<SUP
>31</SUP
> identifiers over the
     lifetime of the table. The type names <TT
CLASS="TYPE"
>smallserial</TT
> and
     <TT
CLASS="TYPE"
>serial2</TT
> also work the same way, except that they
     create a <TT
CLASS="TYPE"
>smallint</TT
> column.
    </P
><P
>     The sequence created for a <TT
CLASS="TYPE"
>serial</TT
> column is
     automatically dropped when the owning column is dropped.
     You can drop the sequence without dropping the column, but this
     will force removal of the column default expression.
    </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="datatype.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="datatype-money.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Data Types</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="datatype.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Monetary Types</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>