我在其中一个表中声明了一个类型为"time without time zone"的字段。问题是时间(通过JDBC)以毫秒为单位存储,这是我不想要的。
09:55:10.137
我们只需要秒(为了使应用程序兼容并在基于DB2的环境中运行,在该环境中时间仅以秒为单位存储)
09:55:10
我可以改变这个字段吗?如何改变?
由于stackoverflow这在文档中有描述。不带时区的时间戳可以指定为:
timestamp [ (p) ] [ without time zone ]
其中p
要求精度
引用文档:
测试:time、timestamp和interval接受一个可选的精度值p类型中保留的小数位数秒字段。默认情况下,对精度没有显式的限制。时间戳和时间间隔的取值范围为0到6类型。
drop table if exists test;
-- zero fractional digits after seconds
create table test(mytime timestamp(0) without time zone);
-- now() returns current time including microseconds
insert into test values(now());
select * from test;
----
2014-06-05 10:42:11