Unverified 提交 59288b3d authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #912 from katzyn/float

Check precision for FLOAT data type and describe it in documentation
......@@ -2412,10 +2412,11 @@ DECIMAL(20, 2)
"
"Data Types","DOUBLE Type","
{ DOUBLE [ PRECISION ] | FLOAT | FLOAT8 }
{ DOUBLE [ PRECISION ] | FLOAT [ ( precisionInt ) ] | FLOAT8 }
","
A floating point number. Should not be used to represent currency values, because
of rounding problems.
If precision value is specified for FLOAT type name, it should be from 25 to 53.
Mapped to ""java.lang.Double"".
","
......@@ -2423,10 +2424,11 @@ DOUBLE
"
"Data Types","REAL Type","
{ REAL | FLOAT4 }
{ REAL | FLOAT ( precisionInt ) | FLOAT4 }
","
A single precision floating point number. Should not be used to represent currency
values, because of rounding problems.
Precision value for FLOAT type name should be from 0 to 24.
Mapped to ""java.lang.Float"".
","
......
......@@ -4446,6 +4446,18 @@ public class Parser {
}
read(")");
}
} else if (dataType.type == Value.DOUBLE && original.equals("FLOAT")) {
if (readIf("(")) {
int p = readPositiveInt();
read(")");
if (p > 53) {
throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(p));
}
if (p <= 24) {
dataType = DataType.getDataType(Value.FLOAT);
}
original = original + '(' + p + ')';
}
} else if (dataType.type == Value.ENUM) {
if (readIf("(")) {
java.util.List<String> enumeratorList = new ArrayList<>();
......
......@@ -2,3 +2,31 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE MEMORY TABLE TEST(D1 DOUBLE, D2 DOUBLE PRECISION, D3 FLOAT, D4 FLOAT(25), D5 FLOAT(53));
> ok
ALTER TABLE TEST ADD COLUMN D6 FLOAT(54);
> exception
SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
> COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_TYPE
> ----------- --------- --------- ----------------
> D1 8 DOUBLE DOUBLE
> D2 8 DOUBLE DOUBLE PRECISION
> D3 8 DOUBLE FLOAT
> D4 8 DOUBLE FLOAT(25)
> D5 8 DOUBLE FLOAT(53)
> rows (ordered): 5
SCRIPT NODATA NOPASSWORDS NOSETTINGS TABLE TEST;
> SCRIPT
> --------------------------------------------------------------------------------------------------------
> -- 0 +/- SELECT COUNT(*) FROM PUBLIC.TEST;
> CREATE MEMORY TABLE PUBLIC.TEST( D1 DOUBLE, D2 DOUBLE PRECISION, D3 FLOAT, D4 FLOAT(25), D5 FLOAT(53) );
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> rows: 3
DROP TABLE TEST;
> ok
......@@ -2,3 +2,30 @@
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE MEMORY TABLE TEST(D1 REAL, D2 FLOAT4, D3 FLOAT(0), D4 FLOAT(24));
> ok
ALTER TABLE TEST ADD COLUMN D5 FLOAT(-1);
> exception
SELECT COLUMN_NAME, DATA_TYPE, TYPE_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
> COLUMN_NAME DATA_TYPE TYPE_NAME COLUMN_TYPE
> ----------- --------- --------- -----------
> D1 7 REAL REAL
> D2 7 REAL FLOAT4
> D3 7 REAL FLOAT(0)
> D4 7 REAL FLOAT(24)
> rows (ordered): 4
SCRIPT NODATA NOPASSWORDS NOSETTINGS TABLE TEST;
> SCRIPT
> ---------------------------------------------------------------------------------
> -- 0 +/- SELECT COUNT(*) FROM PUBLIC.TEST;
> CREATE MEMORY TABLE PUBLIC.TEST( D1 REAL, D2 FLOAT4, D3 FLOAT(0), D4 FLOAT(24) );
> CREATE USER IF NOT EXISTS SA PASSWORD '' ADMIN;
> rows: 3
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论