【发布时间】:2015-07-01 00:11:04
【问题描述】:
我已阅读此在线 PostgreSQL 文档...http://www.postgresql.org/docs/9.4/static/datatype-datetime.html#INTERVAL-STYLE-OUTPUT-TABLE 在第 8.5.5 点中关于如何调整默认间隔输出的内容。 .我的意思是默认间隔是这样显示的......
00:00:00.000 (if the timedifference is lower than a day or month or year)
1 day 00:00:00.000 (if the timedifference reaches days, but is lower than a month or a year)
1 month 1 day 00:00:00.000 (if the timediffence reaches months, but is lower than a year)
1 year 1 month 1 day 00:00:00.000 (if it reaches years, months, days)
it evens uses plurarl cases (years, mons, days) when their values are greater than one.
在选择(查询)此间隔值(作为文本)将其转换为适当的时间时,所有这些变化都会难以进行任何其他应用。所以我希望 postgresql 总是显示年、月 n 天,即使它们的值为 0(如果它可以像这样显示间隔的日期部分可能会更好...... 01-11-30,添加零到值小于十时的左侧)
我知道我可以使用 to_char() 将时间间隔更改为文本,但我真的想避免这种情况,我希望一些优秀的 postgresql 程序员告诉我是否有办法调整时间间隔输出如 postgresql 文档中所述。
感谢高级。
PD:关于该主题的另外两个链接 https://my.vertica.com/docs/7.1.x/HTML/Content/Authoring/SQLReferenceManual/Statements/SET/SETDATESTYLE.htm http://my.vertica.com/docs/6.1.x/HTML/index.htm#13874.htm
【问题讨论】:
-
我想你已经提到你应该怎么做 - 使用
to_char,或者为间隔格式编写一个(非常简单的)解析器。我认为没有任何支持的方式来修改间隔输出,并且输出必须始终可以被 PostgreSQL 中的间隔 input 函数读取,因此即使您想要也无法实现通用格式表达式一。 -
为什么那些链接(包括 postgresql 文档)谈论“设置间隔输出”?有什么提示吗?谢谢高级。
标签: postgresql intervals