Replace ad-hoc atof() code with call to float4in, per Andrew Dunstan.
This commit is contained in:
parent
85b2facdd8
commit
a1f585139b
|
@ -418,8 +418,7 @@ SELECT '1 e7'::seg AS seg;
|
||||||
ERROR: bad seg representation
|
ERROR: bad seg representation
|
||||||
DETAIL: syntax error at or near "e"
|
DETAIL: syntax error at or near "e"
|
||||||
SELECT '1e700'::seg AS seg;
|
SELECT '1e700'::seg AS seg;
|
||||||
ERROR: syntax error
|
ERROR: "1e700" is out of range for type real
|
||||||
DETAIL: numeric value 1e700 unrepresentable
|
|
||||||
--
|
--
|
||||||
-- testing the operators
|
-- testing the operators
|
||||||
--
|
--
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "fmgr.h"
|
||||||
|
#include "utils/builtins.h"
|
||||||
#include "segdata.h"
|
#include "segdata.h"
|
||||||
|
|
||||||
#undef yylex /* failure to redefine yylex will result in calling the */
|
#undef yylex /* failure to redefine yylex will result in calling the */
|
||||||
|
@ -129,22 +131,13 @@ deviation:
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|
||||||
float seg_atof ( char *value ) {
|
float
|
||||||
float result;
|
seg_atof(char *value)
|
||||||
char *buf = (char *) palloc(256);
|
{
|
||||||
|
Datum datum;
|
||||||
|
|
||||||
errno = 0;
|
datum = DirectFunctionCall1(float4in, CStringGetDatum(value));
|
||||||
sscanf(value, "%f", &result);
|
return DatumGetFloat4(datum);
|
||||||
|
|
||||||
if ( errno ) {
|
|
||||||
snprintf(buf, 256, "numeric value %s unrepresentable", value);
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
||||||
errmsg("syntax error"),
|
|
||||||
errdetail("%s", buf)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue