【问题标题】:Unexpected behavior when converting double precision to text in PostgreSQL在 PostgreSQL 中将双精度转换为文本时出现意外行为
【发布时间】:2017-12-04 16:37:22
【问题描述】:

今天遇到这种奇怪的行为..

select                date_part('year', CURRENT_DATE);
2017
select        to_char(date_part('year', CURRENT_DATE),'9999');
" 2017"
select length(to_char(date_part('year', CURRENT_DATE),'9999'));
5

我当然可以直接使用to_char(CURRENT_DATE,'YYYY'),只是很好奇为什么双精度数字在转换为文本时会在开头有一个空格。 谢谢!


注意事项:

【问题讨论】:

    标签: sql formatting greenplum


    【解决方案1】:

    此行为已记录在案(请参阅examples table)。它为负值的 - 符号留出了空间。

    您似乎可以使用FM 前缀来避免这种情况,即'FM9999'

    【讨论】:

    • 啊,我第一次传球时没听懂。感谢您指出!
    • @Kent 他们还写道:If no explicit provision is made for a sign in to_char()'s pattern, one column will be reserved for the sign, and it will be anchored to (appear just left of) the number. If S appears just left of some 9's, it will likewise be anchored to the number.
    • @krokodilko - 谢谢!我看到这是在最新的 v10 文档中,而在我的文档中却没有。解释的很好
    猜你喜欢
    • 2018-03-02
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-16
    • 2012-09-23
    相关资源
    最近更新 更多