提交 7f313623 authored 作者: Thomas Mueller's avatar Thomas Mueller

The scale was not set correctly in some cases when using CREATE TABLE AS SELECT…

The scale was not set correctly in some cases when using CREATE TABLE AS SELECT if there was no explicit column definition.
上级 68281c15
......@@ -204,9 +204,12 @@ public class CreateTable extends SchemaCommand {
precision = dt.defaultPrecision;
}
int scale = expr.getScale();
if (scale > 0 && (dt.defaultScale == 0 || dt.defaultScale > scale)) {
if (scale > 0 && (dt.defaultScale == 0 || (dt.defaultScale > scale && dt.defaultScale < precision))) {
scale = dt.defaultScale;
}
if (scale > precision) {
precision = scale;
}
Column col = new Column(name, type, precision, scale, displaySize);
addColumn(col);
}
......
......@@ -12,6 +12,7 @@ import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
......@@ -36,6 +37,7 @@ public class TestCases extends TestBase {
}
public void test() throws Exception {
testConvertType();
testSortedSelect();
testMaxMemoryRowsDistinct();
testDeleteTop();
......@@ -90,13 +92,25 @@ public class TestCases extends TestBase {
deleteDb("cases");
}
private void testConvertType() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("create table test as select cast(0 as dec(10, 2)) x");
ResultSetMetaData meta = stat.executeQuery("select * from test").getMetaData();
assertEquals(2, meta.getPrecision(1));
assertEquals(2, meta.getScale(1));
stat.execute("alter table test add column y int");
conn.close();
}
private void testSortedSelect() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stmt = conn.createStatement();
stmt.execute("create memory temporary table test(id int) not persistent");
stmt.execute("insert into test(id) direct sorted select 1");
stmt.execute("drop table test");
Statement stat = conn.createStatement();
stat.execute("create memory temporary table test(id int) not persistent");
stat.execute("insert into test(id) direct sorted select 1");
stat.execute("drop table test");
conn.close();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论