to_char(FM9.9) bug fix

Started by Karel Zakover 23 years ago5 messages
#1Karel Zak
zakkr@zf.jcu.cz
1 attachment(s)

The patch fix bug described in TODO:

* to_char(0,'FM999.99') returns a period, to_char(1,'FM999.99') does not

NOTE! Please, first apply Neil's patch with to_char() code clean up.

Thanks

Karel

test=# select to_char(0,'FM9.9');
to_char
---------
0.
(1 row)

test=# select to_char(1,'FM9.9');
to_char
---------
1.
(1 row)

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

Attachments:

formatting-09192002.patch.gzapplication/x-gzipDownload
#2Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Karel Zak (#1)
Re: to_char(FM9.9) bug fix

Patch applied. Thanks.

TODO item marked as completed.

---------------------------------------------------------------------------

Karel Zak wrote:

The patch fix bug described in TODO:

* to_char(0,'FM999.99') returns a period, to_char(1,'FM999.99') does not

NOTE! Please, first apply Neil's patch with to_char() code clean up.

Thanks

Karel

test=# select to_char(0,'FM9.9');
to_char
---------
0.
(1 row)

test=# select to_char(1,'FM9.9');
to_char
---------
1.
(1 row)

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

[ Attachment, skipping... ]

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#3Peter Eisentraut
peter_e@gmx.net
In reply to: Karel Zak (#1)
Re: [PATCHES] to_char(FM9.9) bug fix

Karel Zak writes:

test=# select to_char(0,'FM9.9');
to_char
---------
0.
(1 row)

test=# select to_char(1,'FM9.9');
to_char
---------
1.
(1 row)

I find this highly bizzare. The FM modifier means to omit unnecessary
trailing stuff. There is no reasonable business or scientific custom to
leave a trailing point after a number.

Or perhaps a more pragmatic question is, how would I print a number
without the trailing point?

--
Peter Eisentraut peter_e@gmx.net

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#3)
Re: [PATCHES] to_char(FM9.9) bug fix

Peter Eisentraut <peter_e@gmx.net> writes:

Karel Zak writes:

test=# select to_char(0,'FM9.9');
to_char
---------
0.
(1 row)

test=# select to_char(1,'FM9.9');
to_char
---------
1.
(1 row)

I find this highly bizzare.

No doubt, but it's what Oracle does (see tests posted to the lists by
several people) and to_char exists to duplicate Oracle behavior. This
is hardly the silliest aspect of to_char's definition, IMHO ...

regards, tom lane

#5Karel Zak
zakkr@zf.jcu.cz
In reply to: Peter Eisentraut (#3)
Re: [PATCHES] to_char(FM9.9) bug fix

On Fri, Sep 20, 2002 at 09:24:00PM +0200, Peter Eisentraut wrote:

Karel Zak writes:

test=# select to_char(0,'FM9.9');
to_char
---------
0.
(1 row)

test=# select to_char(1,'FM9.9');
to_char
---------
1.
(1 row)

I find this highly bizzare. The FM modifier means to omit unnecessary

In the code it's commented as "terrible Ora format" :-)

trailing stuff. There is no reasonable business or scientific custom to
leave a trailing point after a number.

I think so. I don't know who can use format number like '1.' or '.0'.
Can somebody explain why Oracle implement it, who use it?

Or perhaps a more pragmatic question is, how would I print a number
without the trailing point?

Don't use FM or use FM9.0

Examples:

'SVRMGR' = Oracle8 Release 8.0.5.0.0
'test=#' = PostgreSQL 7.3b1

test=# select to_char(1, 'FM9.9');
to_char
---------
1.

SVRMGR> select to_char(1, 'FM9.9') from dual;
TO_C
----
1.

test=# select to_char(1, '9.9');
to_char
---------
1.0

SVRMGR> select to_char(1, '9.9') from dual;
TO_C
----
1.0

test=# select to_char(1, 'FM9.0');
to_char
---------
1.0

SVRMGR> select to_char(1, 'FM9.0') from dual;
TO_C
----
1.0

--
Karel Zak <zakkr@zf.jcu.cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz