From: | Michael Glaesemann <grzm(at)seespotcode(dot)net> |
---|---|
To: | Seb <spluque(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: length of return value of to_char() |
Date: | 2011-05-21 06:12:13 |
Message-ID: | C7DE39B3-2B30-4A8D-BA34-34FC46D264C2@seespotcode.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Devrim GÜNDÜZ | 2011-05-21 06:45:57 | Re: Error compiling sepgsql in PG9.1 |
Previous Message | Seb | 2011-05-21 06:00:15 | length of return value of to_char() |