FAQ
Hi,

I thought this should be equal to 4:

# SELECT length(to_char(11, '0999'));
length
--------
5
(1 row)

but the string returned by the to_char() call is 0011 (length 4). What
am I missing?

Thanks,

--
Seb

Search Discussions

  • Michael Glaesemann at May 21, 2011 at 6:12 am

    On May 21, 2011, at 2:00, Seb wrote:

    Hi,

    I thought this should be equal to 4:

    # SELECT length(to_char(11, '0999'));
    length
    --------
    5
    (1 row)

    but the string returned by the to_char() call is 0011 (length 4). What
    am I missing?
    There's a preceeding space:

    postgres=# SELECT length(to_char(11, '0999'));
    length
    --------
    5
    (1 row)

    postgres=# SELECT to_char(11, '0999');
    to_char
    ---------
    0011
    (1 row)

    postgres=# SELECT quote_literal(to_char(11, '0999'));
    quote_literal
    ---------------
    ' 0011'
    (1 row)

    Compare using Fill Mode (FM):

    postgres=# SELECT quote_literal(to_char(11, 'FM0999'));
    quote_literal
    ---------------
    '0011'
    (1 row)

    See the documentation for more details:
    <http://www.postgresql.org/docs/9.0/interactive/functions-formatting.html#FUNCTIONS-FORMATTING-NUMERIC-TABLE>

    Michael Glaesemann
    grzm seespotcode net
  • Seb at May 21, 2011 at 1:48 pm

    On Sat, 21 May 2011 02:12:13 -0400, Michael Glaesemann wrote: [...]
    There's a preceeding space:
    [...]

    Thanks! Good to have quote_literal in mind for this.

    --
    Seb

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-general @
categoriespostgresql
postedMay 21, '11 at 6:00a
activeMay 21, '11 at 1:48p
posts3
users2
websitepostgresql.org
irc#postgresql

2 users in discussion

Seb: 2 posts Michael Glaesemann: 1 post

People

Translate

site design / logo © 2022 Grokbase