Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit35d50b5

Browse files
committed
Fix to_number() to correctly ignore thousands separator when it's '.'.
The existing code in NUM_numpart_from_char has hard-wired logic to treat'.' as decimal point, even when we're using a locale-aware format stringand the locale says that '.' is the thousands separator. This results inclearly wrong answers in FM mode (where we must be able to identify thedecimal point location), as per bug report from Patryk Kordylewski.Since the initialization code in NUM_prepare_locale already sets upNp->decimal as either the locale decimal-point string or "." dependingon which decimal-point format code was used, there's really no need tohave any extra logic at all in NUM_numpart_from_char: we only need totest for a match to Np->decimal.(Note: AFAICS there's nothing in here that explicitly checks for thousandsseparators --- rather, any unmatched character is silently skipped over.That's pretty bogus IMO but it's not the issue being complained of.)This is a longstanding bug, but it's possible that some existing appsare depending on '.' being recognized as decimal point even when usinga D format code. Hence, no back-patch. We should probably list thisas a potential incompatibility in the 9.3 release notes.
1 parent8cade04 commit35d50b5

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

‎src/backend/utils/adt/formatting.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,7 +4131,7 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
41314131
#endif
41324132

41334133
/*
4134-
* read digit
4134+
* read digit or decimal point
41354135
*/
41364136
if (isdigit((unsignedchar)*Np->inout_p))
41374137
{
@@ -4151,40 +4151,28 @@ NUM_numpart_from_char(NUMProc *Np, int id, int plen)
41514151
#ifdefDEBUG_TO_FROM_CHAR
41524152
elog(DEBUG_elog_output,"Read digit (%c)",*Np->inout_p);
41534153
#endif
4154-
4155-
/*
4156-
* read decimal point
4157-
*/
41584154
}
41594155
elseif (IS_DECIMAL(Np->Num)&&Np->read_dec== FALSE)
41604156
{
4157+
/*
4158+
* We need not test IS_LDECIMAL(Np->Num) explicitly here, because
4159+
* Np->decimal is always just "." if we don't have a D format token.
4160+
* So we just unconditionally match to Np->decimal.
4161+
*/
4162+
intx=strlen(Np->decimal);
4163+
41614164
#ifdefDEBUG_TO_FROM_CHAR
4162-
elog(DEBUG_elog_output,"Try read decimal point (%c)",*Np->inout_p);
4165+
elog(DEBUG_elog_output,"Try read decimal point (%c)",
4166+
*Np->inout_p);
41634167
#endif
4164-
if (*Np->inout_p=='.')
4168+
if (x&&AMOUNT_TEST(x)&&strncmp(Np->inout_p,Np->decimal,x)==0)
41654169
{
4170+
Np->inout_p+=x-1;
41664171
*Np->number_p='.';
41674172
Np->number_p++;
41684173
Np->read_dec= TRUE;
41694174
isread= TRUE;
41704175
}
4171-
else
4172-
{
4173-
intx=strlen(Np->decimal);
4174-
4175-
#ifdefDEBUG_TO_FROM_CHAR
4176-
elog(DEBUG_elog_output,"Try read locale point (%c)",
4177-
*Np->inout_p);
4178-
#endif
4179-
if (x&&AMOUNT_TEST(x)&&strncmp(Np->inout_p,Np->decimal,x)==0)
4180-
{
4181-
Np->inout_p+=x-1;
4182-
*Np->number_p='.';
4183-
Np->number_p++;
4184-
Np->read_dec= TRUE;
4185-
isread= TRUE;
4186-
}
4187-
}
41884176
}
41894177

41904178
if (OVERLOAD_TEST)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp