Brendan Jurd escribió: > Here's version 6 of the EEEE patch, now with an all-new implementation > of (normalised) scientific notation in numeric.c, via the functions > numeric_out_sci() and get_str_from_var_sci(). So EEEE should now be > able to represent the full gamut of the numeric type.
I noticed an ugly pattern in NUMDesc_prepare calling a cleanup function before every ereport(ERROR). I think it's cleaner to replace that with a PG_TRY block; see attached. I didn't go over the patch in much more detail. (But the numeric_out_sci business got me thinking.) -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.
Index: src/backend/utils/adt/formatting.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/adt/formatting.c,v retrieving revision 1.159 diff -c -p -r1.159 formatting.c *** src/backend/utils/adt/formatting.c 6 Jul 2009 19:11:39 -0000 1.159 --- src/backend/utils/adt/formatting.c 9 Aug 2009 07:23:34 -0000 *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1044,1059 **** if (n->type != NODE_TYPE_ACTION) return; switch (n->key->id) { case NUM_9: if (IS_BRACKET(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("\"9\" must be ahead of \"PR\""))); - } if (IS_MULTI(num)) { ++num->multi; --- 1044,1058 ---- if (n->type != NODE_TYPE_ACTION) return; + PG_TRY(); + { switch (n->key->id) { case NUM_9: if (IS_BRACKET(num)) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("\"9\" must be ahead of \"PR\""))); if (IS_MULTI(num)) { ++num->multi; *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1067,1078 **** case NUM_0: if (IS_BRACKET(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("\"0\" must be ahead of \"PR\""))); - } if (!IS_ZERO(num) && !IS_DECIMAL(num)) { num->flag |= NUM_F_ZERO; --- 1066,1074 ---- *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1096,1114 **** num->need_locale = TRUE; case NUM_DEC: if (IS_DECIMAL(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("multiple decimal points"))); - } if (IS_MULTI(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"V\" and decimal point together"))); - } num->flag |= NUM_F_DECIMAL; break; --- 1092,1104 ---- *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1118,1136 **** case NUM_S: if (IS_LSIGN(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"S\" twice"))); - } if (IS_PLUS(num) || IS_MINUS(num) || IS_BRACKET(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"S\" and \"PL\"/\"MI\"/\"SG\"/\"PR\" together"))); - } if (!IS_DECIMAL(num)) { num->lsign = NUM_LSIGN_PRE; --- 1108,1120 ---- *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1148,1159 **** case NUM_MI: if (IS_LSIGN(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"S\" and \"MI\" together"))); - } num->flag |= NUM_F_MINUS; if (IS_DECIMAL(num)) num->flag |= NUM_F_MINUS_POST; --- 1132,1140 ---- *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1161,1172 **** case NUM_PL: if (IS_LSIGN(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"S\" and \"PL\" together"))); - } num->flag |= NUM_F_PLUS; if (IS_DECIMAL(num)) num->flag |= NUM_F_PLUS_POST; --- 1142,1150 ---- *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1174,1197 **** case NUM_SG: if (IS_LSIGN(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"S\" and \"SG\" together"))); - } num->flag |= NUM_F_MINUS; num->flag |= NUM_F_PLUS; break; case NUM_PR: if (IS_LSIGN(num) || IS_PLUS(num) || IS_MINUS(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"PR\" and \"S\"/\"PL\"/\"MI\"/\"SG\" together"))); - } num->flag |= NUM_F_BRACKET; break; --- 1152,1169 ---- *************** NUMDesc_prepare(NUMDesc *num, FormatNode *** 1207,1227 **** case NUM_V: if (IS_DECIMAL(num)) - { - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"V\" and decimal point together"))); - } num->flag |= NUM_F_MULTI; break; case NUM_E: - NUM_cache_remove(last_NUMCacheEntry); ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("\"E\" is not supported"))); } return; } --- 1179,1202 ---- case NUM_V: if (IS_DECIMAL(num)) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("cannot use \"V\" and decimal point together"))); num->flag |= NUM_F_MULTI; break; case NUM_E: ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("\"E\" is not supported"))); } + } + PG_CATCH(); + { + NUM_cache_remove(last_NUMCacheEntry); + PG_RE_THROW(); + } + PG_END_TRY(); return; }
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers