pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bug when retrieving money datatype.
5+ messages / 5 participants
[nested] [flat]

* Bug when retrieving money datatype.
@ 2011-11-29 21:36 Thomas Kellerer <spam_eater@gmx.net>
  2011-11-29 21:51 ` Re: Bug when retrieving money datatype. Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Thomas Kellerer @ 2011-11-29 21:36 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

columns with type "money" are reported as Types.DOUBLE by the JDBC driver.

However using ResultSet.getDouble() (or getObject()) on those columns throws an error:

Bad value for type double : €100,00
(SQL State=22003)

It seems that for money columns, only getString() works properly which doesn't really make sense. It breaks applications which assume that ResultSet.getDouble() can be used on a column that is identified as Types.DOUBLE

I would at least expect ResultSet.getObject() to work properly on those columns.

Regards
Thomas




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Bug when retrieving money datatype.
  2011-11-29 21:36 Bug when retrieving money datatype. Thomas Kellerer <spam_eater@gmx.net>
@ 2011-11-29 21:51 ` Oliver Jowett <oliver@opencloud.com>
  2011-11-30 06:55   ` Re: Bug when retrieving money datatype. Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Oliver Jowett @ 2011-11-29 21:51 UTC (permalink / raw)
  To: Thomas Kellerer <spam_eater@gmx.net>; +Cc: pgsql-jdbc

On 30 November 2011 10:36, Thomas Kellerer <spam_eater@gmx.net> wrote:

> Bad value for type double : €100,00

Looks like an internationalization problem - the code that handles
parsing money values isn't expecting a euro sign, just a dollar sign.
Is there a standard way to correctly interpret money values formatted
by the server when the client's locale might be different to the
server's?

Oliver



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Bug when retrieving money datatype.
  2011-11-29 21:36 Bug when retrieving money datatype. Thomas Kellerer <spam_eater@gmx.net>
  2011-11-29 21:51 ` Re: Bug when retrieving money datatype. Oliver Jowett <oliver@opencloud.com>
@ 2011-11-30 06:55   ` Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
  2011-11-30 14:36     ` Re: Bug when retrieving money datatype. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Mikko Tiihonen @ 2011-11-30 06:55 UTC (permalink / raw)
  To: pgsql-jdbc

On 11/29/2011 11:51 PM, Oliver Jowett wrote:
> On 30 November 2011 10:36, Thomas Kellerer<spam_eater@gmx.net>  wrote:
>
>> Bad value for type double : €100,00
>
> Looks like an internationalization problem - the code that handles
> parsing money values isn't expecting a euro sign, just a dollar sign.
> Is there a standard way to correctly interpret money values formatted
> by the server when the client's locale might be different to the
> server's?

I was planning to add the binary format support for money to the
jdbc driver when I had some free time. It will solve all parsing
problems related to locale and give nice speed boost at the same time.

The current way is a hack where the generic number parsing knows how to
ignore $ and (). Of course we should also fix the text format parsing.

In both cases I think the correct way is to handle the money as a
PGmoney type in jdbc driver.

Here is my mental list of what should be improved around the PGmoney:
- Use BigDecimal instead of double
- Support sending the text format in the server locale
- Proper conversion when requested with getBigDecimal, getDouble,
   getInt, getLong in the driver
- Making sure getString of money type will no longer return the $/€ or
   whatever currency the user might have
- add binary encoding support

-Mikko



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Bug when retrieving money datatype.
  2011-11-29 21:36 Bug when retrieving money datatype. Thomas Kellerer <spam_eater@gmx.net>
  2011-11-29 21:51 ` Re: Bug when retrieving money datatype. Oliver Jowett <oliver@opencloud.com>
  2011-11-30 06:55   ` Re: Bug when retrieving money datatype. Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
@ 2011-11-30 14:36     ` Tom Lane <tgl@sss.pgh.pa.us>
  2011-11-30 23:46       ` Re: Bug when retrieving money datatype. Craig Ringer <ringerc@ringerc.id.au>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2011-11-30 14:36 UTC (permalink / raw)
  To: Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>; +Cc: pgsql-jdbc

Mikko Tiihonen <mikko.tiihonen@nitorcreations.com> writes:
> I was planning to add the binary format support for money to the
> jdbc driver when I had some free time. It will solve all parsing
> problems related to locale and give nice speed boost at the same time.

I don't think that's exactly a magic bullet.  Yes, it'll mean you don't
need to know the locale's currency symbol or what it uses for decimal
point, but how are you going to determine where the decimal point is
in the binary representation?  You'll still be dependent on knowing the
server's lc_monetary locale.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Bug when retrieving money datatype.
  2011-11-29 21:36 Bug when retrieving money datatype. Thomas Kellerer <spam_eater@gmx.net>
  2011-11-29 21:51 ` Re: Bug when retrieving money datatype. Oliver Jowett <oliver@opencloud.com>
  2011-11-30 06:55   ` Re: Bug when retrieving money datatype. Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
  2011-11-30 14:36     ` Re: Bug when retrieving money datatype. Tom Lane <tgl@sss.pgh.pa.us>
@ 2011-11-30 23:46       ` Craig Ringer <ringerc@ringerc.id.au>
  0 siblings, 0 replies; 5+ messages in thread

From: Craig Ringer @ 2011-11-30 23:46 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>; pgsql-jdbc

On 11/30/2011 10:36 PM, Tom Lane wrote:
> Mikko Tiihonen<mikko.tiihonen@nitorcreations.com>  writes:
>> I was planning to add the binary format support for money to the
>> jdbc driver when I had some free time. It will solve all parsing
>> problems related to locale and give nice speed boost at the same time.
> I don't think that's exactly a magic bullet.  Yes, it'll mean you don't
> need to know the locale's currency symbol or what it uses for decimal
> point, but how are you going to determine where the decimal point is
> in the binary representation?  You'll still be dependent on knowing the
> server's lc_monetary locale.

I thought `money' was due to go away at some point? Isn't it about time 
to start logging:

    WARNING: The "money" datatype is deprecated. Use NUMERIC instead.

... whenever MONEY is used in DDL? Issues like locale-dependent 
representation make it all the more painful, and I can't help but wonder 
if it's worth trying to fix it.

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2011-11-30 23:46 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-11-29 21:36 Bug when retrieving money datatype. Thomas Kellerer <spam_eater@gmx.net>
2011-11-29 21:51 ` Oliver Jowett <oliver@opencloud.com>
2011-11-30 06:55   ` Mikko Tiihonen <mikko.tiihonen@nitorcreations.com>
2011-11-30 14:36     ` Tom Lane <tgl@sss.pgh.pa.us>
2011-11-30 23:46       ` Craig Ringer <ringerc@ringerc.id.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox