Bug #517: TO_CHAR(timestamp, 'Day') adds extra whitespace

Started by PostgreSQL Bugs Listover 24 years ago3 messagesbugs
Jump to latest
#1PostgreSQL Bugs List
pgsql-bugs@postgresql.org

Ashley Cambrell (ash@freaky-namuh.com) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
TO_CHAR(timestamp, 'Day') adds extra whitespace

Long Description
Using the postgresql TO_CHAR function with Day, DAY, day, Month, MONTH or month as the text argument, extra whitespace is appended to the output.

It's easy enough to fixup on the client side, but it's pretty annoying.

Sample Code
SELECT TO_CHAR('2001-01-01'::date, 'Month');
to_char
-----------
January
(1 row)

SELECT LENGTH('January');
length
--------
7
(1 row)

SELECT LENGTH(TO_CHAR('2001-01-01'::date, 'Month'));
length
--------
9
(1 row)

ELECT TO_CHAR('2001-01-01'::date, 'Day');
to_char
-----------
Monday
(1 row)

SELECT LENGTH('Monday');
length
--------
6
(1 row)

SELECT LENGTH(TO_CHAR('2001-01-01'::date, 'Day'));
length
--------
9
(1 row)

-- notice requested single space after Monday
SELECT LENGTH('Monday ');
length
--------
7
(1 row)

-- notice requested single space after Day
SELECT LENGTH(TO_CHAR('2001-01-01'::date, 'Day '));
length
--------
10
(1 row)

No file was uploaded with this report

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #517: TO_CHAR(timestamp, 'Day') adds extra whitespace

pgsql-bugs@postgresql.org writes:

Using the postgresql TO_CHAR function with Day, DAY, day, Month, MONTH or month as the text argument, extra whitespace is appended to the output.

AFAIK this is the intended behavior. There's an FM modifier that you
add to the format item to suppress extra whitespace. See the examples
in the manual.

(Yes, this formatting language is plenty ugly, but don't blame us ...
we're just trying to be Oracle-compatible with it ...)

regards, tom lane

#3Ashley Cambrell
ash@freaky-namuh.com
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #517: TO_CHAR(timestamp, 'Day') adds extra whitespace

Tom Lane wrote:

<snip>

regards, tom lane

My bad.. didn't read to the end of the page. Now I feel stupid.. ;-)
Ashley Cambrell

(btw, I submitted a bug to psql-bugs about the
http://www.ca.postgresql.org/bugs/index.php page not working under
mozilla. It said the post got stalled because I'm not on the list. Can
someone have a look at it? [it's an easy fix])