Re: solution! (was: Re: problem with float8 input format)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ldm(at)apartia(dot)ch
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: solution! (was: Re: problem with float8 input format)
Date: 2000-08-12 16:15:26
Message-ID: 22920.966096926@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Louis-David Mitterrand <cunctator(at)apartia(dot)ch> writes:
> When "seller_locale" is, for instance, "de_DE", then I get theses
> errors:
> ERROR: Bad float8 input format '0.05'
> Is Postgres expecting the float as 0,05 (notice the comma) because of
> the locale?

I'm sure that's the issue. If you look at the source of the message
(float8in() in src/backend/utils/adt/float.c) you'll see that it's
just relying on strtod() to parse the input. If your local strtod() is
locale-sensitive then the expected input format changes accordingly.
Not sure whether that's a feature or a bug, but it's how Postgres
has always worked.

IMPORTANT: changing the backend's locale on-the-fly is an EXTREMELY
DANGEROUS thing to do, and I strongly recommend that you find another
way to solve your problem. Running with a different locale changes the
expected sort order for indices, which means that your indices will
become corrupted as items get inserted out of order compared to other
items (for one definition of "order" or the other), leading to failure
to find items that should be found in later searches.

Given that your trigger has been exiting with the changed locale still
in force, I'm surprised your DB is still functional at all (perhaps you
have no indexes on textual columns?). But it'd be extremely dangerous
even if you were to restore the old setting before exit --- what happens
if there's an elog(ERROR) before you can restore?

At present, the only safe way to handle locale is to set it in the
postmaster's environment, never in individual backends. What's more,
you'd better be careful that the postmaster is always started with the
same locale setting for a given database. You can find instances of
people being burnt by this sort of problem in the archives :-(

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Prasanth A. Kumar 2000-08-12 16:34:42 Re: PostgreSQL interfaces for PHP and Perl
Previous Message Kari Lempiainen 2000-08-12 15:59:27 Plans to support database.table syntax?

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-08-12 16:41:10 Re: problem with float8 input format
Previous Message Louis-David Mitterrand 2000-08-12 14:57:17 solution! (was: Re: problem with float8 input format)