summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2004-10-24 21:47:07 +0000
committerTom Lane2004-10-24 21:47:07 +0000
commitd9b27d949e0816042feb7dbfb35f19a1100d1682 (patch)
tree26c57b5362415195222c240178811aeaa12e5596
parente6b4707f2761e5c00d0c08bd601f6427a183f147 (diff)
Replace ad-hoc atof() code with call to float4in, per Andrew Dunstan.
-rw-r--r--contrib/seg/expected/seg.out3
-rw-r--r--contrib/seg/segparse.y23
2 files changed, 9 insertions, 17 deletions
diff --git a/contrib/seg/expected/seg.out b/contrib/seg/expected/seg.out
index cfa8171e68..49f4f7dee5 100644
--- a/contrib/seg/expected/seg.out
+++ b/contrib/seg/expected/seg.out
@@ -418,8 +418,7 @@ SELECT '1 e7'::seg AS seg;
ERROR: bad seg representation
DETAIL: syntax error at or near "e"
SELECT '1e700'::seg AS seg;
-ERROR: syntax error
-DETAIL: numeric value 1e700 unrepresentable
+ERROR: "1e700" is out of range for type real
--
-- testing the operators
--
diff --git a/contrib/seg/segparse.y b/contrib/seg/segparse.y
index d0c2f188bc..8a3b0b0160 100644
--- a/contrib/seg/segparse.y
+++ b/contrib/seg/segparse.y
@@ -5,6 +5,8 @@
#include <math.h>
+#include "fmgr.h"
+#include "utils/builtins.h"
#include "segdata.h"
#undef yylex /* failure to redefine yylex will result in calling the */
@@ -129,22 +131,13 @@ deviation:
%%
-float seg_atof ( char *value ) {
- float result;
- char *buf = (char *) palloc(256);
+float
+seg_atof(char *value)
+{
+ Datum datum;
- errno = 0;
- sscanf(value, "%f", &result);
-
- if ( errno ) {
- snprintf(buf, 256, "numeric value %s unrepresentable", value);
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("syntax error"),
- errdetail("%s", buf)));
- }
-
- return result;
+ datum = DirectFunctionCall1(float4in, CStringGetDatum(value));
+ return DatumGetFloat4(datum);
}