Thread: "invalid input syntax for integer" for number with exponent

"invalid input syntax for integer" for number with exponent

From
Stephen Froehlich
Date:

I’m getting the following error when trying to go from R to a bigint field in PostgreSQL.

 

COPY invalid input syntax for integer: "1.12589990684262e+015"

 

Do I need to convert the number into text manually in R?  Exactly what about this input is confusing PostgreSQL?

 

Thanks,

Stephen

 


Stephen Froehlich
Sr. Strategist, CableLabs®


s.froehlich@cablelabs.com

Tel: +1 (303) 661-3708

 

Re: "invalid input syntax for integer" for number with exponent

From
Bzzzz
Date:
On Wed, 28 Feb 2018 21:16:37 +0000
Stephen Froehlich <s.froehlich@cablelabs.com> wrote:

> I'm getting the following error when trying to go from R to a bigint
> field in PostgreSQL.
> 
> COPY invalid input syntax for integer: "1.12589990684262e+015"
> 
> Do I need to convert the number into text manually in R?  Exactly what
> about this input is confusing PostgreSQL?

Take a closer look at this number: is it a FLOAT, not an integer, thus
you get an error trying to insert a float in an integer column.

JY


Re: "invalid input syntax for integer" for number with exponent

From
"David G. Johnston"
Date:
On Wed, Feb 28, 2018 at 2:24 PM, Bzzzz <lazyvirus@gmx.com> wrote:
On Wed, 28 Feb 2018 21:16:37 +0000
Stephen Froehlich <s.froehlich@cablelabs.com> wrote:

> I'm getting the following error when trying to go from R to a bigint
> field in PostgreSQL.
>
> COPY invalid input syntax for integer: "1.12589990684262e+015"
>
> Do I need to convert the number into text manually in R? Exactly what
> about this input is confusing PostgreSQL?


SELECT '1e4'::integer; -- fails with the same message in PostgreSQL; the text input function for integers doesn't understand scientific notation.

You will need to ensure that R outputs its numbers in non-scientific format in order to copy them into PostgreSQL via an intermediate text file.

Take a closer look at this number: is it a FLOAT, not an integer, thus
you get an error trying to insert a float in an integer column.

​Uh, no, that is not what the error is saying...though it is quite possible if this error wasn't present what you say might happen.  The OP does have confusion somewhere in the schema since the copy command is trying to use integer while the stated desire is bigint.

David J.