提交 c84fe02e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix SQL representation of CAST for types with fractional seconds precision

上级 aad6a418
......@@ -502,7 +502,12 @@ public class Column {
if (originalSQL != null) {
buff.append(originalSQL);
} else {
buff.append(DataType.getDataType(type).name);
DataType dataType = DataType.getDataType(type);
if (type == Value.TIMESTAMP_TZ) {
buff.append("TIMESTAMP");
} else {
buff.append(dataType.name);
}
switch (type) {
case Value.DECIMAL:
buff.append('(').append(precision).append(", ").append(scale).append(')');
......@@ -525,6 +530,16 @@ public class Column {
buff.append('(').append(precision).append(')');
}
break;
case Value.TIME:
case Value.TIMESTAMP:
case Value.TIMESTAMP_TZ:
if (scale != dataType.defaultScale) {
buff.append('(').append(scale).append(')');
}
if (type == Value.TIMESTAMP_TZ) {
buff.append(" WITH TIME ZONE");
}
break;
default:
}
}
......
......@@ -99,3 +99,30 @@ select cast('000102030405060708090a0b0c0d0e0f' as uuid);
select -cast(0 as double);
>> 0.0
SELECT * FROM (SELECT CAST('11:11:11.123456789' AS TIME));
>> 11:11:11
SELECT * FROM (SELECT CAST('11:11:11.123456789' AS TIME(0)));
>> 11:11:11
SELECT * FROM (SELECT CAST('11:11:11.123456789' AS TIME(9)));
>> 11:11:11.123456789
SELECT * FROM (SELECT CAST('2000-01-01 11:11:11.123456789' AS TIMESTAMP));
>> 2000-01-01 11:11:11.123457
SELECT * FROM (SELECT CAST('2000-01-01 11:11:11.123456789' AS TIMESTAMP(0)));
>> 2000-01-01 11:11:11
SELECT * FROM (SELECT CAST('2000-01-01 11:11:11.123456789' AS TIMESTAMP(9)));
>> 2000-01-01 11:11:11.123456789
SELECT * FROM (SELECT CAST('2000-01-01 11:11:11.123456789Z' AS TIMESTAMP WITH TIME ZONE));
>> 2000-01-01 11:11:11.123457+00
SELECT * FROM (SELECT CAST('2000-01-01 11:11:11.123456789Z' AS TIMESTAMP(0) WITH TIME ZONE));
>> 2000-01-01 11:11:11+00
SELECT * FROM (SELECT CAST('2000-01-01 11:11:11.123456789Z' AS TIMESTAMP(9) WITH TIME ZONE));
>> 2000-01-01 11:11:11.123456789+00
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论