README.data_types 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. ---------------------
  2. Native SQL data types
  3. ---------------------
  4. BIGINT (FB 1.5)
  5. --------------
  6. Function:
  7. SQL99-compliant exact numeric type.
  8. Author:
  9. Dmitry Yemanov <[email protected]>
  10. Syntax rules:
  11. BIGINT
  12. Storage:
  13. 64-bit, signed
  14. Example(s):
  15. 1. DECLARE VARIABLE VAR1 BIGINT;
  16. 2. CREATE TABLE TABLE1 (FIELD1 BIGINT);
  17. Note(s):
  18. 1. Available in Dialect 3 only.
  19. 2. Quote from the SQL-99 specification:
  20. SMALLINT, INTEGER, and BIGINT specify the data type exact numeric,
  21. with scale of 0 (zero) and binary or decimal precision. The choice
  22. of binary versus decimal precision is implementation-defined, but
  23. the same radix shall be chosen for all three data types. The precision
  24. of SMALLINT shall be less than or equal to the precision of INTEGER,
  25. and the precision of BIGINT shall be greater than or equal to the
  26. precision of INTEGER.
  27. BOOLEAN (FB 3.0)
  28. --------------
  29. Function:
  30. SQL2008-compliant boolean type.
  31. Author:
  32. Adriano dos Santos Fernandes <adrianosf at gmail.com>
  33. Syntax rules:
  34. BOOLEAN
  35. Storage:
  36. 8-bit
  37. Example(s):
  38. 1. DECLARE VARIABLE VAR1 BOOLEAN = TRUE;
  39. 2. CREATE TABLE TABLE1 (FIELD1 BOOLEAN);
  40. Note(s):
  41. 1. Quote from the SQL-2008 specification:
  42. The data type boolean comprises the distinct truth values TRUE and FALSE. Unless prohibited
  43. by a NOT NULL constraint, the boolean data type also supports the truth value UNKNOWN as the
  44. null value. This specification does not make a distinction between the null value of the
  45. boolean data type and the truth value Unknown that is the result of an SQL <predicate>,
  46. <search condition>, or <boolean value expression>; they may be used interchangeably to mean
  47. exactly the same thing.
  48. 2. Represented in the API with the FB_BOOLEAN type and FB_TRUE and FB_FALSE constants.
  49. 3. The value TRUE is greater than the value FALSE.
  50. 4. Non-booleans values are not implicitly convertible to boolean in boolean-specific expressions
  51. like predicates and arguments for operators NOT, AND, OR and IS.
  52. 5. It's allowed to test booleans without compare with TRUE or FALSE. For example,
  53. "field1 OR field2" and "NOT field1" are valid expressions. It's also allowed to compare with
  54. others operators, including the new IS operator: "field1 IS FALSE".
  55. BINARY, VARBINARY, BINARY VARYING (FB 4.0)
  56. ------------------------------------------
  57. Function:
  58. Alias for CHAR, VARCHAR, VARYING CHAR with CHARACTER SET OCTETS.
  59. Author:
  60. Dimitry Sibiryakov
  61. Syntax rules:
  62. BINARY[(length)]
  63. VARBINARY(length)
  64. BINARY VARYING(length)
  65. Example(s):
  66. 1. DECLARE VARIABLE VAR1 VARBINARY(10);
  67. 2. CREATE TABLE TABLE1 (FIELD1 BINARY(16),
  68. FIELD2 VARBINARY(100),
  69. FIELD3 BINARY VARYING(1000));
  70. Note(s):
  71. 1. If length is omitted for type BINARY, it is considered to be 1.
  72. 2. Can be distinguished from text types by value 1 in RDB$FIELD_SUB_TYPE.
  73. 3. Character set is set to OCTETS for backward compatibility.
  74. 4. In API are similar to corresponding text types, getSubType() returns 0.
  75. DECFLOAT (FB 4.0)
  76. --------------
  77. Function:
  78. DB2-compliant numeric type. DECFLOAT precisely (unlike FLOAT or DOUBLE PRECISION that provide
  79. binary approximation) stores decimal values being therefore ideal choice for business appli-
  80. cations. Firebird according to IEEE standard has both 16- and 34-digit decimal float encodings.
  81. All intermediate calculations are performed with 34-digit values.
  82. Author:
  83. Alex Peshkoff <[email protected]>
  84. Syntax rules:
  85. DECFLOAT
  86. DECFLOAT(16)
  87. DECFLOAT(34)
  88. Storage:
  89. 64-bit / 128-bit, format according to IEEE 754 Decimal64/Decimal128
  90. Example(s):
  91. 1. DECLARE VARIABLE VAR1 DECFLOAT(34);
  92. 2. CREATE TABLE TABLE1 (FIELD1 DECFLOAT(16));
  93. Note(s):
  94. 1. If no precision has been specified in the type declaration, the precision is 34.
  95. 2. A number of standard functions can be used with DECFLOAT datatype. It is:
  96. ABS, CEILING, EXP, FLOOR, LN, LOG, LOG10, POWER, SIGN, SQRT.
  97. Agregate functions SUM, AVG, MAX and MIN also work with DECFLOAT data.
  98. All statistics aggregates (like but not limited to STDDEV or CORR) work with DECFLOAT data.
  99. 3. Firebird supports four functions, specially designed to support DECFLOAT data:
  100. - COMPARE_DECFLOAT - compares two DECFLOAT values to be equal, different or unordered.
  101. Returns SMALLINT value which can be as follows:
  102. 0 - values are equal
  103. 1 - first value is less than second
  104. 2 - first value is greater than second
  105. 3 - values unordered (i.e. one or both is NAN / SNAN)
  106. Unlike comparison operators ('<', '=', '>', etc.) comparison is exact - i.e.
  107. COMPARE_DECFLOAT(2.17, 2.170) returns 2, not 0.
  108. - NORMALIZE_DECFLOAT - has single DECFLOAT argument returned in it's simplest form. That
  109. means that for any nonzero value trailing zero are removed with appropriate correction
  110. of an exponent. For example NORMALIZE_DECFLOAT(12.00) returns 12 and
  111. NORMALIZE_DECFLOAT(120) returns 1.2E+2.
  112. - QUANTIZE - has two DECFLOAT arguments. The returned value is first argument scaled using
  113. second value as a pattern. For example QUANTIZE(1234, 9.999) returns 1234.000.
  114. - TOTALORDER - compares two DECFLOAT values including any special value. The comparison is
  115. exact. Returns SMALLINT value which can be as follows:
  116. -1 - first value is less than second
  117. 0 - values are equal
  118. 1 - first value is greater than second
  119. DECFLOAT values are ordered as follows:
  120. -nan < -snan < -inf < -0.1 < -0.10 < -0 < 0 < 0.10 < 0.1 < inf < snan < nan
  121. 4. Firebird supports new session control operator SET DECFLOAT. It has following forms:
  122. SET DECFLOAT ROUND <mode> - controls rounding mode used in operations with DECFLOAT
  123. values. Valid modes are: CEILING (towards +infinity), UP (away from 0), HALF_UP
  124. (to nearest, if equidistant - up), HALF_EVEN (to nearest, if equidistant - ensure
  125. last digit in the result to be even), HALF_DOWN (to nearest, if equidistant - down),
  126. DOWN (towards 0), FLOOR (towards -infinity), REROUND (up if digit to be rounded is
  127. 0 or 5, down in other cases). HALF_UP rounding is used by default.
  128. The initial configuration may be specified with DPB isc_dpb_decfloat_round followed
  129. by a string with its value (case does not matter).
  130. SET DECFLOAT TRAPS TO <comma-separated traps list - may be empty> - controls which
  131. exceptional conditions cause a trap. Valid traps are: Division_by_zero, Inexact,
  132. Invalid_operation, Overflow and Underflow. By default traps are set to:
  133. Division_by_zero, Invalid_operation, Overflow.
  134. The initial configuration may be specified with DPB isc_dpb_decfloat_traps followed
  135. by a comma-separated string with its value (case does not matter; using a single
  136. optional space after commas).
  137. 5. The length of DECFLOAT literals are limited to 1024 characters. For longer values, you will
  138. need to use the scientific notation. For example, the 0.0<1020 zeroes>11 cannot be used
  139. as a literal, instead you can use the equivalent in scientific notation: 1.1E-1022.
  140. Similarly 10<1022 zeroes>0 can be presented as 1.0E1024.
  141. Enhancement in precision of calculations with NUMERIC/DECIMAL (FB 4.0)
  142. --------------
  143. Function:
  144. Maximum precision of NUMERIC and DECIMAL data types is increased to 38 digits.
  145. Author:
  146. Alex Peshkoff <[email protected]>
  147. Syntax rules:
  148. INT128
  149. NUMERIC ( P {, N} )
  150. DECIMAL ( P {, N} )
  151. where P is precision (P <= 38, was limited prior with 18 digits) and N is optional number
  152. of digits after decimal separator (as before).
  153. Storage:
  154. 128-bit signed integer.
  155. Example(s):
  156. 1. DECLARE VARIABLE VAR1 DECIMAL(25);
  157. 2. CREATE TABLE TABLE1 (FIELD1 NUMERIC(38, 19));
  158. 3. CREATE PROCEDURE PROC1 (PAR1 INT128) AS BEGIN END;
  159. Note(s):
  160. Numerics with precision less than 19 digits use SMALLINT, INTEGER, BIGINT or DOUBLE PRECISION
  161. as base datatype depending upon number of digits and dialect. When precision is between 19 and
  162. 38 digits 128-bit integer is used for it. Actual precision is always increased to 38 digits.
  163. For complex calculations such digits are casted (internally) to DECFLOAT(34) and the result of
  164. various math (log, exp, etc.) and aggregate functions using high precision numeric argument is
  165. DECFLOAT(34).