在PostgreSQL下,我PersistentDuration用于sql类型间隔和持续时间之间的映射,但它不起作用.
另一位用户发现了同样的问题,并附带了自己的课程:
public void nullSafeSet(PreparedStatement statement, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
statement.setNull(index, Types.OTHER);
} else {
Long interval = ((Long) value).longValue();
Long hours = interval / 3600;
Long minutes = (interval - (hours * 3600)) / 60;
Long secondes = interval - (hours * 3600) - minutes * 60;
statement.setString(index, "'"+ hours +":"
+ intervalFormat.format(minutes) + ":"
+ intervalFormat.format(secondes)+"'");
}
}
Run Code Online (Sandbox Code Playgroud)
但它不适用于真实格式,因为它假设间隔模式只是"hh:mm:ss".事实并非如此:见
这里有一些我需要从数据库中解析的实例:
1 day 00:29:42 00:29:42 1 week 00:29:42 …
根据他们的网站,DUration类实现了ISO 8601
http://en.wikipedia.org/wiki/ISO_8601#Durations
但让我们看一个例子.持续时间为14分钟和51秒.在ISO 8601中,这些代码是等效的:
System.out.println("bug "+new Duration("PT14M51S"));
System.out.println("NO bug "+new Duration("PT891S");
Run Code Online (Sandbox Code Playgroud)
PT14M51S是postgresql数据库的真正摘录并且正确.joda-time api只是将所有内容转换为秒为什么?它似乎不知道任何东西比关键字S(theres Y,M,D ...)
提前致谢
我有两个表A和B,我希望有一个查询:如果两个表相同,则返回TRUE(我的意思是A中的每一行都存在于B中,反之亦然,无论行顺序如何)
我使用了关键字EXCEPT但它在许多情况下都不起作用
谢谢你的帮助.
postgresql ×2
column-types ×1
custom-type ×1
duration ×1
hibernate ×1
intervals ×1
jodatime ×1
sql ×1